I test a program below:
#include <stdio.h>
#include <stdlib.h>
typedef struct _node_t {
int id;
int contents[0];
}node_t;
int
main(int argc, char* argv[])
{
printf("sizeof node_t is: %d\n", sizeof (struct _node_t)); // output: 4
node_t *node = (node_t*)malloc(sizeof(node_t) + sizeof(int) * 3);
printf("sizeof node is: %d\n", sizeof (node)); // output: 8
return 0;
}
And the size of node instant is 8. However, in the malloc
function, I put extra 3 integers to the node
structure. Why the output of node size is still 8?
PS: gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)