Suggestion: class/struct tuples preserve anonymous unions/structs
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Feb 15 14:04:52 PST 2007
Sean Kelly wrote:
> Frits van Bommel wrote:
>> Walter Bright wrote:
>>> Jarrett Billingsley wrote:
>>>> I'm not sure how anonymous unions and structs are handled by the
>>>> compiler.
>>>
>>> This has nothing to do with tuples. Anonymous structs and unions are
>>> used for layout only, the members are 'promoted' into the enclosing
>>> aggregate.
>>
>> It's fairly obvious this is what's happening. And normally this
>> wouldn't matter as you wouldn't be able see the difference, but
>> because of ..tupleof this is now detectable.
>> I think the real question here is: while this may be what *is*
>> happening, is this also what *should* happen? (i.e. "Is this a bug?")
>> I can't find anything specifying this behavior in the spec...
>
> I think as long as .offsetof can be obtained for the values then
> everything should be fine. You know members are part of a union when
> their .offsetof is the same.
Yeah, you can figure it out like this, but I do think exposing anonymous
structs and unions as actual struct an union members would lead to
cleaner code for some cases. Even if this only happens when it's nested
in an aggregate of the other type (or a union in a class).
More information about the Digitalmars-d
mailing list