Variable attributes (IBM extension)

A variable attribute is a language extension that allows you to use a named attribute to specify special properties of variables. Currently, only the variable attribute aligned is supported on the z/OS® platform.

A variable attribute is specified with the keyword __attribute__ followed by the attribute name and any additional arguments the attribute name requires. A variable __attribute__ specification is included in the declaration of a variable, and can be placed before or after the declarator. Although there are variations, the syntax generally takes either of the following forms:

Read syntax diagramSkip visual syntax diagram
Variable attribute syntax: post-declarator

>>-declarator--__attribute__------------------------------------>

       .-,----------------------.       
       V                        |       
>--((----+-attribute name-----+-+--))--------------------------><
         '-__attribute name__-'         

Read syntax diagramSkip visual syntax diagram
Variable attribute syntax: pre-declarator

>>-type specifier--__attribute__-------------------------------->

       .-,----------------------.                   
       V                        |                   
>--((----+-attribute name-----+-+--))--declarator--------------->
         '-__attribute name__-'                     

>--+-------------+---------------------------------------------><
   '-initializer-'   

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. For unsupported attribute names, the z/OS XL C/C++ compiler issues diagnostics and ignores the attribute specification. Multiple attribute names can be specified in the same attribute specification.

In a comma-separated list of declarators on a single declaration line, if a variable attribute appears before all the declarators, it applies to all declarators in the declaration. If the attribute appears after a declarator, it only applies to the immediately preceding declarator. For example:
struct A  {

	int b __attribute__((aligned));          /* typical placement of variable */
                                                         /* attribute */

	int __attribute__((aligned))__ c = 10;   /* variable attribute can also be */
                                            /* placed here */

	int d, e, f __attribute__((aligned));    /* attribute applies to f only */

	int g __attribute__((aligned)), h, i;    /* attribute applies to g only */

	int __attribute__((aligned)) j, k, l;    /* attribute applies to j, k, and l */ 
 
 };

The following variable attributes are supported: