This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Size of structs with zero-length arrays?
- To: gcc-help at gcc dot gnu dot org
- Subject: Size of structs with zero-length arrays?
- From: Nenad Nedeljkovic <nedeljko at yahoo dot com>
- Date: Wed, 11 Jul 2001 10:55:18 -0700 (PDT)
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/