Use the alignment attribute to specify how objects of a specific type should be aligned.
typedef long SignedLong __attribute__ ((aligned (8))); SignedLong sl1; /* aligned on a 8-byte boundary */ SignedLong sl2; /* aligned on a 8-byte boundary */However, if an array is declared that contains elements of type SignedLong, such as, for instance: SignedLong v[5]; the alignment attribute will only have effect upon the array itself, not its individual elements. Variable 'v' will be aligned on an 8-byte boundary, but its elements will not (the size of the array will be 20, not 40). If the declaration of the array also uses an alignment attribute, specifying a different alignment than that of the type of the elements. For instance:
SignedLong v[5] __attribute__ ((aligned (64)));the array attribute will prevail. Variable 'v' will be aligned on a 64-byte boundary. The following typedef declaration aligns all instances of struct SimpleStruct on a 4-byte boundary.
typedef struct
{
char x;
char y;
long z;
} SimpleStruct __attribute__ ((aligned(8)));
SimpleStruct s1; /* aligned on an 8-byte boundary */
SimpleStruct s2; /* aligned on an 8-byte boundary */