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:

Variable attribute syntax: post-declarator


1  declarator  __attribute__  ((
2.1+ ,
2.1 attribute name
2.1 __attribute name__
1 ))

Variable attribute syntax: pre-declarator


1  type specifier  __attribute__  ((
2.1+ ,
2.1 attribute name
2.1 __attribute name__
1 ))  declarator?  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;           /* 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: