GCC attribute syntax

GCC attribute syntax allows non-standard properties of functions, variables, types and namespace to be expressed. The attribute syntax serves a similar purpose to #pragma in other compilers, but (at the time the syntax was designed) has the advantage that attributes could be generate be preprocessor macros. Since C99, #pragma can be generated from macros using the _Pragma operator.

Properties expressed with attributes include structure padding and alignment, properties of function behaviour (e.g. that it will never return, or accepts a printf format string), calling convention, etc.

The general form of __attribute__ usage is:

__attribute__((attributename[(param1 [,pparam2 ...])]))

Attributes may appear on struct/class/union definitions, on function declarations and on object definitions. For example,

int printf(char const *, ...) __attribute__((format(printf, 1, 2)));

See GCC Function Attributes, GCC Variable Attributes, GCC Type Attributes and GCC C++ Attributes for information on specific attributes

See also 'info gcc' for detailed information on attributes supported by a particulur version of the gcc toolset.

Intel C/C++ and Sun Studio also support the attribute syntax.