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.
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.
- initialized or static global or namespace variables
- static local variables
- uninitialized global or namespace variables
- 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.
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.
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.