This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On alignment
Jason Merrill <jason at redhat dot com> writes:
| On 23 Apr 2003 12:11:24 -0600, Tom Tromey <tromey at redhat dot com> wrote:
|
| >>>>>> "Jason" == Jason Merrill <jason at redhat dot com> writes:
| >
| > [ about struct foo { double x; } ]
| >
| > Tom> I'd like to find the most future-proof way to do this. In the above,
| > Tom> is __alignof__(foo::x) the best way? I'm only concerned with
| > Tom> alignment of fields.
| >
| > Jason> It is since my recent patch to do all alignment calculation for
| > Jason> fields in layout_decl.
| >
| > I can't do this.
| >
| > struct aligner { double field; };
| >
| > int compute () { return __alignof__ (aligner::field); }
|
| Ah, no, you need to do something like
|
| #define FIELD_ALIGNOF(TYPE) __alignof (((struct { TYPE t; } *)0)->t)
Hmm, when tested like
#include <iostream>
#define FIELD_ALIGNOF(TYPE) __alignof (((struct { TYPE t; } *)0)->t)
int main()
{
std::cout << FIELD_ALIGNOF(double) << std::endl;
}
I get:
j.C: In function `int main()':
j.C:7: error: types may not be defined in casts
I think the template-based solution I posted in another message solves
the problem...
-- Gaby