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


> -----Original Message-----
> From: gcc-owner On Behalf Of Mark Mitchell
> Sent: 19 January 2005 00:33

> Steven L. Zook wrote:
> > "As such, they are ambiguous."
> > 
> > That seems a little harsh :-(
> 
> No; uDerf::A is ambiguous.  Which one is it?  You seem to be 
> seeing that 
> you want the A in the two anonymous structs to be merged together. 

  In C, that's what the 'union' kind of implies, isn't it?  In the presence of
"common initial sequences" ?

--------------------<snip!>--------------------
6.5.2.3.5 (n2794)
One special guarantee is made in order to simplify the use of unions: If a union
contains several structures that share a common initial sequence (see below),
and if the union object currently contains one of these structures, it is
permitted to inspect the common initial part of any of them anywhere that a
declaration of the completed type of the union is visible. Two structures share
a common initial sequence if corresponding members have compatible types (and,
for bit-fields, the same widths) for a sequence of one or more initial members.
--------------------<snip!>--------------------

  What seems to me to be a real bug is that gcc (3.3.3) will accept the
following variant in C:

--------------------<snip!>--------------------
dk@mace /test/derf> cat derf.c

union uDerf { struct { unsigned char A;
                       unsigned      B;
                     };
              struct { unsigned char D;
                       long          A;
                     };
            };

dk@mace /test/derf> gcc -c derf.c -o derf
dk@mace /test/derf> g++ -c derf.c -o derf
In file included from derf.c:8:
derf.c:7: error: declaration of `long int uDerf::<anonymous struct>::A'
derf.c:3: error: conflicts with previous declaration `unsigned char
   uDerf::<anonymous struct>::A'
dk@mace /test/derf>
--------------------<snip!>--------------------

where the initial sequences are *not* compatible.  That's bad, m'kay?

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


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