4.8 constseg Pragma

The IAR constseg pragma changes the segment in which const data is 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 a const object 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 constseg=HI_MARK
const int factorySettings[] = {40, 51, 127, 0};
#pragma constseg=default
to MPLAB XC8 code similar to:
#include <xc.h>
const int __section("HI_MARK") factorySettings[] = {42, 15, -128, 0};
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.