This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On alignment
On 23 Apr 2003 13:39:49 -0600, Tom Tromey <tromey at redhat dot com> wrote:
>>>>>> "Gabriel" == Gabriel Dos Reis <gdr at integrable-solutions dot net> writes:
>
> Gabriel> #define FIELD_ALIGNOF(TYPE) __alignof (((struct { TYPE t; } *)0)->t)
>
> Gabriel> j.C: In function `int main()':
> Gabriel> j.C:7: error: types may not be defined in casts
Ah, yes. I was using a C testcase.
> In that message you said that you got "8" as the answer for a double
> field on x86. That's not the answer I'm looking for :-(. On x86, a
> double field has alignment 4, while a non-field double has alignment 8.
> In the libgcj context, we're only ever laying out structures, so we need
> to get "4" as the answer. The above does do that.
Again, this currently only works in the trunk.
A similar trick using offsetof should work with all versions of gcc; just
add a char field to the beginning of the struct, and measure the offset to
the TYPE field.
Jason