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.

IBM® XL C compiler implements a subset of the GNU C function attributes. For a particular function attribute that is not implemented, the compiler issues diagnostics and ignores the attribute specification.

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:

Read syntax diagramSkip visual syntax diagram
Function attribute syntax: function definition (form 1)

>>-return_type--__attribute__----------------------------------->

       .-,--------------------------.       
       V                            |       
>--((----+-attribute name---------+-+--))----------------------->
         '-__--attribute_name--__-'         

>--function_declarator-----------------------------------------><

Read syntax diagramSkip visual syntax diagram
Function attribute syntax: function definition (form 2)

>>-__attribute__------------------------------------------------>

       .-,--------------------------.                                            
       V                            |                                            
>--((----+-attribute_name---------+-+--))--return_type--function_declarator--;-><
         '-__--attribute_name--__-'                                              

Read syntax diagramSkip visual syntax diagram
Function attribute syntax: function definition (form 3)

>>-return_type--function_declarator--__attribute__-------------->

       .-,--------------------------.          
       V                            |          
>--((----+-attribute_name---------+-+--))--;-------------------><
         '-__--attribute_name--__-'            

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

The following function attributes are supported:



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us