This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On alignment
- From: Jamie Lokier <jamie at shareable dot org>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Andrew Haley <aph at redhat dot com>, Jason Merrill <jason at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 23 Apr 2003 13:49:44 +0100
- Subject: Re: On alignment
- References: <200303251122.13693.kevin.hendricks@sympatico.ca> <wvl1y0vmhdv.fsf@prospero.boston.redhat.com> <wvlu1drl2kl.fsf@prospero.boston.redhat.com> <200303251344.59988.kevin.hendricks@sympatico.ca> <wvlhe9rkzgm.fsf@prospero.boston.redhat.com> <16037.6826.35777.756256@cuddles.redhat.com> <jen0ii4x27.fsf@sykes.suse.de>
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