This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On alignment
- From: Tom Tromey <tromey at redhat dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Gabriel Dos Reis <gdr at integrable-solutions dot net>, Jamie Lokier <jamie at shareable dot org>, gcc at gcc dot gnu dot org
- Date: 01 May 2003 17:42:45 -0600
- Subject: Re: On alignment
- References: <200303251122.13693.kevin.hendricks@sympatico.ca><wvl1y0vmhdv.fsf@prospero.boston.redhat.com><wvlu1drl2kl.fsf@prospero.boston.redhat.com><200303251344.59988.kevin.hendricks@sympatico.ca><wvlhe9rkzgm.fsf@prospero.boston.redhat.com><16037.6826.35777.756256@cuddles.redhat.com><jen0ii4x27.fsf@sykes.suse.de><20030423124944.GA24593@mail.jlokier.co.uk><87wuhlgq5l.fsf@fleche.redhat.com><wvlu1cpdv7s.fsf@prospero.boston.redhat.com><87lly1f5ir.fsf@fleche.redhat.com><wvllly1dq6q.fsf@prospero.boston.redhat.com><m3ist5auzc.fsf@uniton.integrable-solutions.net><87sms9dmuy.fsf@fleche.redhat.com><wvlptncd0i2.fsf@prospero.boston.redhat.com><16039.44856.826662.680167@cuddles.redhat.com>
- Reply-to: tromey at redhat dot com
>>>>> "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