Type attributes are language extensions provided to facilitate compilation of programs developed with the GNU C compiler 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, and typedef definitions. 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. Although there are variations, the syntax of a type attribute is of the general form:
Type attribute syntax — aggregate types >>-+-struct-+--__attribute__------------------------------------> +-union--+ '-enum---' >--((--+----------------------------------------+--))-----------> | .-,----------------------------------. | | V | | '---attribute name--__attribute name__-+-' >--+----------------+--{--member_definition_list--}--;--------->< '-tag_identifier-'
Type attribute syntax — typedef declarations >>-typedef--type_declaration--type_name-------------------------> >--__attribute__--((--+----------------------------------------+--))--;->< | .-,----------------------------------. | | V | | '---attribute name--__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 compiler issues diagnostics and ignores the attribute specification. Multiple attribute names can be specified in the same attribute specification.