Frits van Bommel wrote:
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.

Or the least common multiple, assuming that align accepts arguments that are not powers of 2.

Reply via email to