Hi everyone,
I'm going to tell you how I think calloc() works. If I'm wrong, and I think I am because it doesn't work the way I expect, PLEASE try to explain where my mistake is. Thank you all in advance!
So what we have is void *calloc( size_t num, size_t size );
According to me, the later means:
"Allocate memory block with size 'num * size'. I expect that this memory block is divided into 'num' smaller blocks, 'size' bytes each. So I expect to be able to fill this big block with say 'num' strings, each of them with size 'size'.
Simple example to make it clearer:
char *base = (char *)calloc( 3, 10 * sizeof(char));
base[0] = "123456789";
base[1] = "123456789";
base[2] = "123456789";
When I try to compile this with gcc version 3.3 on MacOS X I get the following mistake:
lea:~/Documents admin$ gcc -o memtest1 memtest1.c
memtest1.c: In function `main':
memtest1.c:5: warning: assignment makes integer from pointer without a cast
memtest1.c:6: warning: assignment makes integer from pointer without a cast
memtest1.c:7: warning: assignment makes integer from pointer without a cast
Help me. Tell me where I am wrong! Thank you once again!
I'm going to tell you how I think calloc() works. If I'm wrong, and I think I am because it doesn't work the way I expect, PLEASE try to explain where my mistake is. Thank you all in advance!
So what we have is void *calloc( size_t num, size_t size );
According to me, the later means:
"Allocate memory block with size 'num * size'. I expect that this memory block is divided into 'num' smaller blocks, 'size' bytes each. So I expect to be able to fill this big block with say 'num' strings, each of them with size 'size'.
Simple example to make it clearer:
char *base = (char *)calloc( 3, 10 * sizeof(char));
base[0] = "123456789";
base[1] = "123456789";
base[2] = "123456789";
When I try to compile this with gcc version 3.3 on MacOS X I get the following mistake:
lea:~/Documents admin$ gcc -o memtest1 memtest1.c
memtest1.c: In function `main':
memtest1.c:5: warning: assignment makes integer from pointer without a cast
memtest1.c:6: warning: assignment makes integer from pointer without a cast
memtest1.c:7: warning: assignment makes integer from pointer without a cast
Help me. Tell me where I am wrong! Thank you once again!