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


Steven L. Zook wrote:
Consider these declarations:

union uFred { struct { unsigned char A;
                       unsigned      B;
                     };
              struct { unsigned char C;
                       long          D;
                     };
            };
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++.


--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304


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