24.4.13 Assigning Objects to Sections

The __section() specifier can be used to indicate that an object should be located in the named section. This is typically used when the object has special and unique linking requirements that cannot be addressed by existing compiler features.

Use the native keywords discussed in the Differences section to look up information on the semantics of this specifier.

Example

The following shows a variable which uses the __section keyword.

int __section(“comSec”) commonFlag;

Differences

The 8-bit compilers have previously used the #pragma psect directive to redirect objects to a new section, or psect; however, the __section() specifier is the preferred method to perform this task, even if you are not using the CCI.

The 16- and 32-bit compilers have used the section attribute to indicate a different destination section name. The __section() specifier works in a similar way to the attribute.

Migration to the CCI

For MPLAB XC8, change any occurrence of the #pragma psect directive, such as:

#pragma psect text%%u=myText
int getMode(int target) {
//...
}

to the __section() specifier, as in:

int __section ("myText") getMode(int target) {
//...
}

For 16- and 32-bit compilers, change any occurrence of the section attribute, for example, from:

int __attribute__((section(“myVars”))) intMask;

to:

int __section(“myVars”) intMask;

Caveats

None.