On alignment

Tom Tromey tromey@redhat.com
Wed Apr 23 18:42:00 GMT 2003


>>>>> "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); }

fleche. gcc -c y.cc
y.cc: In function `int compute()':
y.cc:1: error: invalid use of non-static data member `aligner::field'
y.cc:3: error: from this location


I can use __alignof__(aligner), but my concern is that eventually this
will yield "8" instead of "4" on x86.  libgcj really needs to know the
alignment required in structures, for compatibility with the compiler.
Preferably we'd have the compiler tell us this info.

Tom



More information about the Gcc mailing list