On alignment
Tom Tromey
tromey@redhat.com
Wed Apr 23 20:23:00 GMT 2003
>>>>> "Gabriel" == Gabriel Dos Reis <gdr@integrable-solutions.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
I got that too, but I worked around it like so:
template<typename T>
struct aligner
{
T field;
};
#define ALIGNOF(TYPE) (__alignof__ (((aligner<TYPE> *) 0)->field))
Gabriel> I think the template-based solution I posted in another
Gabriel> message solves the problem...
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.
Tom
More information about the Gcc
mailing list