On alignment

Jamie Lokier jamie@shareable.org
Thu Apr 24 01:32:00 GMT 2003


Tom Tromey wrote:
>     struct aligner { double field; };
>     int compute () { return __alignof__ (aligner::field); }
> 
> I can use __alignof__(aligner), but my concern is that eventually this
> will yield "8" instead of "4" on x86.

When __alignof__(aligner) returns 8, you may find that
__alignof__(((aligner *)0)->field) returns 8 also.  The __alignof__
operator on a structure field doesn't report "alignment for structure
layout purposes", it reports "alignment of this object (the field) in
memory", which would be 8.  Think about it.

-- Jamie



More information about the Gcc mailing list