This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Size of structs with zero-length arrays?


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]