Anonymous structs with duplicate members within unions

Mark Mitchell mark@codesourcery.com
Wed Jan 19 17:48:00 GMT 2005


Dave Korn wrote:
>>-----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" ?

No, that's a separate issue regarding type compatibility.  The issue 
here is simply that you can't have two data members named uDerf::A.   If 
the structs were not anonymous, then there would be no problem.  C++ has 
special handling for anonymous unions; G++ has extended that to 
anonymous structs.  In both case, things declared in the anonymous 
objects are (for naming purposes) declared in the containing object.

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



More information about the Gcc mailing list