4.10 dataseg Pragma

The IAR dataseg pragma changes the segment in which objects are placed. Any arbitrary named segment can be provided, and default restores placement to the default segment.

Suggested Replacement

There is no equivalent MPLAB XC8 pragma, but there is an attribute that performs a similar task.

The MPLAB XC8 section attribute can be used with objects to specify the section in which it is placed. If the Common C Interface is enabled, you can instead use the __section specifier.

Caveats

The sections generated by this attribute are not concatenated across translation units by the linker, and the -Wl,--section-start,section_name=address option, which can place a section in memory, only works with custom (non-standard) sections.

Examples

Consider migrating IAR code such as:
#pragma dataseg=US_SEG
int swOffset;
#pragma dataseg=default
to MPLAB XC8 code similar to:
#include <xc.h>
int __section("US_SEG") swOffset;
and build with the -mext=cci option.

Further Information

See the Attributes and Ext Option section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on this attribute.