This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

Re: GCC C bug: sizeof a union of structs returns zero value


-----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-----


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