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


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

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


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