The great inapplicable attribute debate

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Apr 14 06:17:26 PDT 2009


Stewart Gordon wrote:
> Don wrote:
>> Stewart Gordon wrote:
> <snip>
>>> Surely, align isn't applicable to unions at all.  IINM the members of 
>>> a union, by design, start at the same offset.
>>
>> Not so, the alignment of each member should be respected. 
> 
> But the offset of a union member is always zero.  So what would this do?

It should make sure the union is aligned appropriately in a containing struct, 
meaning U.alignof >= M.alignof for all members M. Specifying per-member 
alignment allows you to change that member's effect on the union's alignment.

>> Most obviously, a union U consisting of a single member x should have
>> U.alignof == x.alignof.
> <snip>
> 
> Yes, by propagating the union's alignment (relative to the containing 
> struct) to the member.

But the union's alignment needs to be sufficient for all members, so it depends 
on the maximum alignment of all members.



More information about the Digitalmars-d mailing list