This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On alignment


Andreas Schwab wrote:
> Andrew Haley <aph at redhat dot 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]