The section variable attribute

The section variable attribute specifies the section in the object file in which the compiler should place its generated code. The language feature provides the ability to control the section in which a variable should appear.

Read syntax diagramSkip visual syntax diagram
section variable attribute syntax

>>-declarator--------------------------------------------------->

>--__attribute__--((--+-section-----+--(--"--section_name--"--)--))-><
                      '-__section__-'                                 

The section_name specifies a named section as a string literal, maximum length of 16 characters, not counting spaces. Spaces in the string are ignored.

The section variable attribute can be applied to a declaration or definition of the following types of variables:
  • initialized or static global or namespace variables
  • static local variables
  • C++ only uninitialized global or namespace variables
  • C++ only static structure or class member variables

A section attribute applied to a local variable with automatic storage duration is ignored with a warning because such variables are stored on the stack.

C only begins A section attribute applied to a structure member is ignored with a warning. A section attribute applied to an uninitialized global variable is ignored without a warning; the symbols for uninitialized global variables are always placed in the common section.C only ends

When multiple section attributes are applied to a variable declaration, the last specification prevails. The section indicated in the prevailing variable declaration should match that of the variable definition because a variable definition cannot be overwritten. Each defined variable can reside in only one section.

The section attribute overrides the -fcommon | -fno-common (-qcommon | -qnocommon) compiler option and the common|nocommon attribute. That is, if both attributes are specified for the same variable, the section attribute takes priority.

A named section can be used for multiple variables, but not for both variables and functions in the same compilation unit.



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