Function attributes (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:

Function attribute syntax: function definition (form 1)

Read syntax diagramSkip visual syntax diagramreturn_type__attribute__(( ,attribute name__attribute_name__ ))function_declarator

Function attribute syntax: function definition (form 2)

Read syntax diagramSkip visual syntax diagram__attribute__(( ,attribute_name__attribute_name__ ))return_typefunction_declarator ;

You can specify attribute_name with or without leading and trailing double underscore characters; however, using the double underscore characters reduces the likelihood of name conflicts with macros of the same name. These language features are collectively available when compiling in any of the extended language levels.

The following function declarations are all valid:
int __attribute__((attribute_name)) func(int i);   //Form 1
__attribute__((attribute_name)) int func(int);     //Form 2
int func() __attribute__((attribute_name));        //Form 3
C++ only beginsThe attribute specification must follow any exception declaration that might present for the function. For example:
int func(int) throw(int) __attribute__((pure));
C++ only ends

The following function attributes are supported: