Type attribute aligned allows you to specify the alignment of a structure, class, union, or enumeration. The syntax and considerations for specifying alignment factor are the same as for variable attribute aligned. Like variable attribute aligned, type attribute aligned can only increase alignment. Type attribute packed is used to decrease alignment.
If the attribute appears immediately after the class, struct, union, or enumeration token or immediately after the closing right curly brace, it applies to the type identifier. It can also be specified on a typedef declaration. In a variable declaration, such as
class A {} a;
the placement of the type attribute can be confusing.
In the following definitions, the attribute applies to A:
struct __attribute__((__aligned__(8))) A {};
struct A {} __attribute__((__aligned__(8))) ;
struct __attribute__((__aligned__(8))) A {} a;
struct A {} __attribute__((__aligned__(8))) a;
typedef struct __attribute__((__aligned__(8))) A {} a;
typedef struct A {} __attribute__((__aligned__(8))) a;
In the following definitions, the attribute applies to a:
__attribute__((__aligned__(8))) struct A {} a;
struct A {} const __attribute__((__aligned__(8))) a;
__attribute__((__aligned__(8))) typedef struct A {} a;
typedef __attribute__((__aligned__(8))) struct A {} a;
typedef struct A {} const __attribute__((__aligned__(8))) a;
typedef struct A {} a __attribute__((__aligned__(8)));