On alignment

Jason Merrill jason@redhat.com
Wed Apr 23 19:13:00 GMT 2003


On 23 Apr 2003 12:11:24 -0600, Tom Tromey <tromey@redhat.com> wrote:

>>>>>> "Jason" == Jason Merrill <jason@redhat.com> writes:
>
> [ about  struct foo { double x; } ]
>
> Tom> I'd like to find the most future-proof way to do this.  In the above,
> Tom> is __alignof__(foo::x) the best way?  I'm only concerned with
> Tom> alignment of fields.
>
> Jason> It is since my recent patch to do all alignment calculation for
> Jason> fields in layout_decl.
>
> I can't do this.
>
>     struct aligner { double field; };
>
>     int compute () { return __alignof__ (aligner::field); }

Ah, no, you need to do something like

#define FIELD_ALIGNOF(TYPE) __alignof (((struct { TYPE t; } *)0)->t)

Jason



More information about the Gcc mailing list