Attributes (Using the GNU Compiler Collection (GCC)) (original) (raw)


6.4 Attributes Specific to GCC

Attributes provide a mechanism to declare additional properties of functions, variables, types, and statements. For example, attributes can be used to control placement of objects in particular memory sections, or to specify properties that can allow the compiler to generate better code or diagnostics, such as declaring that a function never returns. GCC supports a large number of such attributes, which are documented in this section.

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::’ namespace prefix on attribute names. The traditional syntax, described in detail in Attribute Syntax, is supported in all non-strict C and C++ language dialects. The standard syntax is supported in C with -std=c23 or later, in C++ with -std=c++11 or later, and as an extension in older GNU C and C++ dialects.