This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: GCC C bug: sizeof a union of structs returns zero value
- From: Hugh Daniel <hugh at road dot toad dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: jcr at apple dot com, mcr at xelerance dot com, hugh at mimosa dot com, pleasant at pobox dot com, dberlin at dberlin dot org
- Date: Fri, 17 Dec 2004 05:43:06 -0800
- Subject: Re: GCC C bug: sizeof a union of structs returns zero value
- Reply-to: hugh at xelerance dot com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
My GCC sizeof a union of structs bug seems to be pilot error after
all...
So Hugh Redelmeier found the actual bug when we were looking at the
various details of memory allocation: we were not declaring any struct
identifiers to take the size of. This is the solution:
char ccc[ sizeof( union{ struct aaa; struct bbb; })];
char ccc[ sizeof( union{ struct aaa ; struct bbb ; })];
char ccc[ sizeof( union{ struct aaa Ignore_Me; struct bbb Ignore_Me_Too; })];
^^^^^^^^^ ^^^^^^^^^^^^^
One might argue that Draft n2794.txt "6.7 Declarations" paragraphs
#2 and #6 are at odds in this case, one saying the lack of an
identifier is an error and the other saying it's optional. I leave
this for you to decide.
I will point out that the behavior of the C compiler has changed and
that this should be documented.
Thanks for GCC folks.
||ugh Daniel
-----BEGIN PGP SIGNATURE-----
Comment: For the matching public key, finger the Reply-To: address.
iQCVAwUBQcLiZ1ZpdJR7FBQRAQKcmQQA67Lx2VmQ3/A6iBhTBVHFxPWQtzcNntg1
R8pZNawG1TmwbklELSl9WGWJP6v9wrUeqvdMzLTDhxQWFJACg972ExSFdUGmCg6+
nq21wDDFiMikTimYflM/XVSa0WV6ZXZHEHwP7gKe9bqOBmTsEuFWGmbsrj7H76X3
jjJHkpL9qpM=
=4XbY
-----END PGP SIGNATURE-----