You can use attributes to specify various special
properties of types. Some type attributes apply only to structure and
union types, and in C++, also class types, while others can apply to
any type defined via a typedef
declaration. Unless otherwise
specified, the same restrictions and effects apply to attributes regardless
of whether a type is a trivial structure or a C++ class with user-defined
constructors, destructors, or a copy assignment.
Other attributes are defined for functions (see Declaring Attributes of Functions), labels (see Label Attributes), enumerators (see Enumerator Attributes), statements (see Statement Attributes), and for variables (see Specifying Attributes of Variables).
GCC provides two different ways to specify attributes: the traditional GNU syntax using ‘__attribute__ ((...))’ annotations, and the newer standard C and C++ syntax using ‘[[...]]’ with the ‘gnu::’ prefix on attribute names. Note that the exact rules for placement of attributes in your source code are different depending on which syntax you use. See Attribute Syntax, for details.
You may specify type attributes in an enum, struct or union type
declaration or definition by placing them immediately after the
struct
, union
or enum
keyword. You can also place
them just past the closing curly brace of the definition, but this is less
preferred because logically the type should be fully defined at
the closing brace. You can also include type attributes in a
typedef
declaration.