The aligned type attribute
With the aligned type attribute, you can override the default alignment mode to specify a minimum alignment value, expressed as a number of bytes, for a structure, classes, union, enumeration, or other user-defined type created in a typedef declaration. The aligned attribute is typically used to increase the alignment of any variables declared of the type to which the attribute applies.
aligned type attribute syntax >>-__attribute__------------------------------------------------> >--((--+-aligned-----+--+------------------------+--))--------->< '-__aligned__-' '-(--alignment_factor--)-'The alignment_factor is the number of bytes, specified as a constant expression that evaluates to a positive power of 2. If you omit the alignment factor (and its enclosing parentheses), the compiler automatically uses 16 bytes. You can specify a value up to a maximum 268435456 bytes. If you specify an alignment factor greater than the maximum, the compiler issues an error message and the compilation fails.
The alignment value that you specify is applied to all instances of the type. Also, the alignment value applies to the variable as a whole; if the variable is an aggregate, the alignment value applies to the aggregate as a whole, not to the individual members of the aggregate.
Example
In all of the
following examples, the aligned attribute is applied
to the structure type A. Because a is
declared as a variable of type A, it also
receives the alignment specification, as any other instances
declared of type A.
struct __attribute__((__aligned__(8))) A {};
struct __attribute__((__aligned__(8))) A {} a;
typedef struct __attribute__((__aligned__(8))) A {} a;