This is the mail archive of the gcc@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: Anonymous structs with duplicate members within unions


"As such, they are ambiguous."

That seems a little harsh :-(

Since the two declarations of A in the union uDerf represent the same
type, size, and offset, is the term ambiguous fair? 

Perhaps redundant would be closer to the truth: clearly uDerf::A can
only refer to one actual thing.

I know this sounds like a quibble, but as an extension, might tolerating
a redundant declaration might be considered a reasonable thing to do
whereas tolerating a ambiguous declaration is not?

-----Original Message-----
From: Mark Mitchell [mailto:mark@codesourcery.com] 
Sent: Tuesday, January 18, 2005 2:03 PM
To: Steven L. Zook
Cc: gcc@gcc.gnu.org
Subject: Re: Anonymous structs with duplicate members within unions

<snip...>
> union uDerf { struct { unsigned char A;
>                        unsigned      B;
>                      };
>               struct { unsigned char A;
>                        long          D;
>                      };
>             };

uDerf is invalid ISO C++; there is no such thing as an anonymous struct
in that language.  As a GNU extension, the anonymous structs are treated
like the standard anonymous unions; the fields are directly accessible
as uDerf::A.  As such, they are ambiguous.  Thus, if you replaced
"struct" with "union" in the above code, your code would be invalid ISO 
C++.  That's why it is also rejected in GNU C++.



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