On alignment

Jamie Lokier jamie@shareable.org
Wed Apr 23 13:32:00 GMT 2003


Andreas Schwab wrote:
> Andrew Haley <aph@redhat.com> writes:
> |> WHat I still cannot understand is why a struct that contains a double
> |> is 4-aligned on x86, but a double is 8-aligned.  This means that you
> |> cannot infer the alignment of a struct from the alignment of its
> |> members.  Is this really part of the multi-vendor ABI?
> 
> The alignment of a struct member determines the amount of padding that
> must be inserted, thus it is important to maintain the exact alignment
> requirements of the ABI.  For simple variables there is no such
> requirement, there is never a problem when a standalone variable is
> overaligned.

For the same reason, "struct foo { double x; }" as a standalone
variable should have alignment 8, not 4.  Andrew's test shows it has
an alignment of 4.

Exactly like "double", "struct foo" should have size and alignment 8,
but when it's a field in a larger structure it should pack with alignment 4.

-- Jamie



More information about the Gcc mailing list