-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalloc.c
39 lines (33 loc) · 815 Bytes
/
calloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* =====================================================================================
*
* Filename: calloc.c
*
* Description: calloc vs malloc
*
* Version: 1.0
* Created: 12/11/2016 11:46:10 AM
* Compiler: gcc
*
* Author: Miroslav Tisma [email protected]
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
int main(int argc, char** argv)
{
size_t huge = INTPTR_MAX;
void* buf = malloc(huge * huge);
if (!buf)
perror("malloc failed");
printf("malloc(huge * huge) returned: %p\n", buf);
free(buf);
buf = calloc(huge, huge);
if (!buf)
perror("calloc failed");
printf("calloc(huge, huge) returned: %p\n", buf);
free(buf);
return 0;
}