Size of structs with zero-length arrays?
Nenad Nedeljkovic
nedeljko@yahoo.com
Wed Jul 11 10:55:00 GMT 2001
Here's a code snippet with a zero-length array and the result of
execution after compiling with gcc 2.95.2 or 3.0.1 on x86 Linux:
------------------------------------------------------------------
struct zero { int a[0]; };
struct zero four = { {1, 2, 3, 4} };
struct zero five = { {5, 6, 7, 8, 9} };
main()
{
printf("sizeof(struct zero) = %u\n", sizeof(struct zero));
printf("sizeof(four) = %u\n", sizeof(four));
printf("sizeof(five) = %u\n", sizeof(five));
}
------------------------------------------------------------------
sizeof(struct zero) = 0
sizeof(four) = 0
sizeof(five) = 0
------------------------------------------------------------------
Is this the expected behaviour? If so, isn't it a bit strange,
given that both variables do take space in memory?
Thanks,
Nenad
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
More information about the Gcc-help
mailing list