Function attributes

IBM Extension Beginning of IBM® Extension.

Function attributes are extensions implemented to enhance the portability of programs developed with GNU C. Specifiable attributes for functions provide explicit ways to help the compiler optimize function calls and to instruct it to check more aspects of the code. Others provide additional functionality.

A function attribute is specified with the keyword __attribute__ followed by the attribute name and any additional arguments the attribute name requires. A function __attribute__ specification is included in the declaration or definition of a function. The syntax takes the following forms:

C Beginning of C only.

Function attribute syntax: function definition

Read syntax diagramSkip visual syntax diagram__attribute__(( ,attribute name__attribute_name__ ))function_declarator {function body}

C End of C only.

C++ Beginning of C++ only.

Function attribute syntax: function definition

Read syntax diagramSkip visual syntax diagramfunction declarator __attribute__(( ,attribute_name__attribute_name__ ));

C++ End of C++ only.

The function attribute in a function declaration is always placed after the declarator, including the parenthesized parameter declaration:
/* Specify the attribute on a function prototype declaration */
void f(int i, int j) __attribute__((individual_attribute_name));
void f(int i, int j) { }

C++ Beginning of C++ only.

In C++, the attribute specification must also follow any exception declaration that may be present for the function.

C++ End of C++ only.

C Beginning of C only.

Due to ambiguities in parsing old-style parameter declarations, a function definition must have the attribute specification precede the declarator:
int __attribute__((individual_attribute_name)) foo(int i) { }

C End of C only.

C++A function attribute specification using the form __attribute_name__ (that is, the attribute name with double underscore characters leading and trailing) reduces the likelihood of a name conflict with a macro of the same name.

Related information

IBM Extension End of IBM Extension.