c/language/attributes

Introduces implementation-defined attributes for types, objects, expressions, etc.



Formally, the syntax is

where is a comma-separated sequence of zero or more s

@1@ standard attribute, such as @2@ attribute with a namespace, such as @3@ standard attribute with arguments, such as @4@ attribute with both a namespace and an argument list, such as

Explanation
Attributes provide the unified standard syntax for implementation-defined language extensions, such as the GNU and IBM language extensions, Microsoft extension , etc.

An attribute can be used almost everywhere in the C program, and can be applied to almost everything: to types, to variables, to functions, to names, to code blocks, to entire translation units, although each particular attribute is only valid where it is permitted by the implementation: could be an attribute that can only be used with an, and not with a class declaration. could be an attribute that applies to a code block or to a loop, but not to the type, etc. (note these two attributes are fictional examples, see below for the standard and some non-standard attributes)

In declarations, attributes may appear both before the whole declaration and directly after the name of the entity that is declared, in which case they are combined. In most other situations, attributes apply to the directly preceding entity.

Two consecutive left square bracket tokens may only appear when introducing an attribute-specifier or inside an attribute argument.

Besides the standard attributes listed below, implementations may support arbitrary non-standard attributes with implementation-defined behavior. All attributes unknown to an implementation are ignored without causing an error.

Every is reserved for standardization. That is, every non-standard attribute is prefixed by a provided by the implementation, e.g.  and.

Standard attributes
Only the following attributes are defined by the C standard. Every standard attribute whose name is of form can be also spelled as  and its meaning is not changed.

Attribute testing
Checks for the presence of an attribute token named by.

For standard attributes, it will expand to the year and month in which the attribute was added to the working draft (see table below), the presence of vendor-specific attributes is determined by a non-zero integer constant.

can be expanded in the expression of and. It is treated as a defined macro by, and  but cannot be used anywhere else.