IBM extension

Type attributes

Type attributes are language extensions provided to facilitate compilation of programs developed with the GNU C/C++ compilers. These language features allow you to use named attributes to specify special properties of data objects. Type attributes apply to the definitions of user-defined types, such as structures, unions, enumerations, classes. Any variables that are declared as having that type will have the attribute applied to them.

A type attribute is specified with the keyword __attribute__ followed by the attribute name and any additional arguments the attribute name requires. The __attribute__ specification is included in the definition of a user-defined type, and generally precedes the tag identifier. Although there are variations, the syntax of a type attribute is of the general form:

Read syntax diagramSkip visual syntax diagramType attribute syntax
>>-+-struct-+--__attribute__--((--+-attribute name-----+--))---->
   +-union--+                     '-__attribute name__-'

The attribute name can be specified with or without double underscore characters leading and trailing; however, using the double underscore reduces the likelihood of a name conflict with a macro of the same name. For unsupported attribute names, the XL C/C++ compiler issues diagnostics and ignores the attribute specification. Multiple attribute names can be specified in the same attribute specification.

The following type attributes are supported:

Related information