This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Anonymous structs with duplicate members within unions
- From: "Steven L. Zook" <SLZook at Qualstar dot com>
- To: "Mark Mitchell" <mark at codesourcery dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Tue, 18 Jan 2005 16:05:25 -0800
- Subject: 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++.