This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On alignment
- From: Jason Merrill <jason at redhat dot com>
- To: Nicola Pero <nicola at brainstorm dot co dot uk>
- Cc: Andrew Haley <aph at redhat dot com>, Robert Dewar <dewar at gnat dot com>, <nathan at codesourcery dot com>, <shebs at apple dot com>, <gcc at gcc dot gnu dot org>
- Date: Tue, 22 Apr 2003 19:21:21 +0100
- Subject: Re: On alignment
- References: <Pine.LNX.4.44.0304221648080.31614-100000@nicola.brainstorm.co.uk>
On Tue, 22 Apr 2003 17:04:38 +0100 (BST), Nicola Pero <nicola at brainstorm dot co dot uk> wrote:
> At runtime, the ObjC runtime library has information about the struct -
> the type of each member. At the moment, it loops on the struct members,
> and uses __alignof__ on each of them to get the alignment of that member
> inside the struct (then, can read/write the struct members). As far as I
> understand from this discussion, this doesn't work any longer.
If you actually take __alignof the member, this should work fine. If you
do __alignof the type, you will get the larger number.
On Tue, 22 Apr 2003 17:19:28 +0100, Andrew Haley <aph at redhat dot com> wrote:
> It's rather scary. It means, for example, that
>
> template<class T> void copy (T *a, T *b)
> {
> if (__alignof__ (T) >= 8)
> copy_by_dwords (a, b);
> else
> copy_by_bytes (a, b);
> }
>
> won't do what is expected when applied to a member of a struct. I
> suppose we get away with this because the x86 never generates
> alignment traps in such cases.
Exactly. A STRICT_ALIGNMENT target wouldn't do this sort of thing.
Jason