On alignment

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


WHat I still cannot understand is why a struct that contains a double
is 4-aligned on x86, but a double is 8-aligned.  This means that you
cannot infer the alignment of a struct from the alignment of its
members.  Is this really part of the multi-vendor ABI?

Andrew.


#include <stdio.h>

int
main (int argc, char **argv)
{
  typedef struct foo { double x; } foo;
  foo bar;
  printf ("double align %d size %d\n", __alignof__(double), sizeof(double));
  printf ("foo align %d size %d\n", __alignof__(foo), sizeof(foo));
  
  return 0;
}



More information about the Gcc mailing list