Alignment in a Structure Definition

Use the alignment attribute to specify how instances of a structure should be aligned. You must specify a minimum alignment of at least 4 bytes for structures. Specifying a lower number might cause alignment exceptions at runtime.

For example, this definition aligns all definitions of struct S1 on an 8-byte boundary.

struct S1 { short f[3]; } 
      __attribute__ ((aligned (8))); 
  struct S1 s1;
  

The following definition aligns all definitions of struct S2 on a 4-byte boundary.

struct S2 { short f[3]; } 
      __attribute__ ((aligned (1))); 
  struct S2 s2;