On alignment
Tom Tromey
tromey@redhat.com
Thu May 1 23:50:00 GMT 2003
>>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:
Jason> A similar trick using offsetof should work with all versions of
Jason> gcc; just add a char field to the beginning of the struct, and
Jason> measure the offset to the TYPE field.
Andrew> Ah, okay. That sounds pretty neat.
Andrew> Tom, time for the third (or is it fourth) version of your patch. :-)
How will this work? We can't do this:
template<typename T>
struct aligner
{
char dummy;
T field;
}
A plain offsetof(aligner<jbyte>, field) will yield the wrong answer (2
instead of 1). I guess one answer would be "don't bother with byte or
boolean".
What will eventually go wrong with what we have now?
template<typename T>
struct aligner
{
T field;
};
#define ALIGNOF(TYPE) (__alignof__ (((aligner<TYPE> *) 0)->field))
Tom
More information about the Gcc
mailing list