This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On alignment


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]