On alignment

Andrew Haley aph@redhat.com
Tue Apr 22 17:17:00 GMT 2003


Jason Merrill writes:
 > On Tue, 22 Apr 2003 13:37:43 +0100, Andrew Haley <aph@redhat.com> wrote:
 > 
 > > Robert Dewar writes:
 > >  > > That packing rule is part of the i86 psABI
 > >  > 
 > >  > It's still mighty odd, and of course in Ada you have to override this rule
 > >  > since it conflicts with the Ada standard, which requires that the default
 > >  > minimum alignment of a composite be not less than the alignment of any
 > >  > component.
 > >
 > > It's pretty weird in C++.
 > 
 > It's the same in C.  Weird or not, that's what the SVR4 psABI says, so
 > that's what we do.

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.

Andrew.



More information about the Gcc mailing list