Microchip Technology SW006022-2N Data Sheet
Preprocessing
2012 Microchip Technology Inc.
DS52071B-page 205
16.5
PRAGMAS VS. ATTRIBUTES
The MPLAB XC16 C Compiler uses non-ANSI attributes instead of pragmas or qualifi-
ers to locate variables and functions in memory. As a comparison, the PIC18 MCU C
Compiler - also called MPLAB C18 - uses pragmas for sections (code, romdata,
udata
ers to locate variables and functions in memory. As a comparison, the PIC18 MCU C
Compiler - also called MPLAB C18 - uses pragmas for sections (code, romdata,
udata
, idata), interrupts (high-priority and low-priority) and variable locations (bank,
section). The former HI-TECH C Compiler for PIC18 MCUs and the newer MPLAB XC8
compiler use qualifiers or pragmas to perform the same actions.
compiler use qualifiers or pragmas to perform the same actions.
If you are used to using a PIC18 compiler, this section will show how to use XC16 attri-
butes instead. For more on attributes, see Section 6.11 “Variable Attributes” and
Section 10.2.1 “Function Specifiers”.
butes instead. For more on attributes, see Section 6.11 “Variable Attributes” and
Section 10.2.1 “Function Specifiers”.
TABLE 16-6:
C18 PRAGMAS VS. ATTRIBUTES
TABLE 16-7:
PICC18 PRAGMAS AND QUALIFIERS VS. ATTRIBUTES
EXAMPLE 16-1:
SPECIFY AN UNINITIALIZED VARIABLE IN A USER SECTION
IN DATA MEMORY
IN DATA MEMORY
where oldbss is the name of the psect (section) in which the variable would normally
be placed.
be placed.
EXAMPLE 16-2:
LOCATE THE VARIABLE MABONGA AT ADDRESS 0X100 IN
DATA MEMORY
DATA MEMORY
Pragma (MPLAB C18)
Attribute (MPLAB XC16)
#pragma udata [name]
_ _
attribute
_ _
((section ("name")))
#pragma idata [name]
_ _
attribute
_ _
((section ("name")))
#pragma romdata [name]
_ _
attribute
_ _
((space (auto_psv)))
#pragma code [name]
_ _
attribute
_ _
((section ("name"),
space (prog)))
#pragma interruptlow
_ _
attribute
_ _
((interrupt))
#pragma interrupt
_ _
attribute
_ _
((interrupt, shadow))
#pragma varlocate bank
NA*
#pragma varlocate name
NA*
*
16-bit devices do not have banks.
PICC18
Attribute (MPLAB XC16)
#pragma psect old=new
_ _
attribute
_ _
((section ("name")))
const
const
or
__attribute_ _ ((space (auto_psv)))
interrupt low_priority
_ _
attribute
_ _
((interrupt))
interrupt
_ _
attribute
_ _
((interrupt, shadow))
PICC18 #pragma psect oldbss=mybss
int gi;
C18
#pragma udata mybss
int gi;
XC16
int _ _attribute_ _((_ _section_ _(".mybss"))) gi;
PICC18 int Mabonga @ 0x100;
C18
#pragma idata myDataSection=0x100;
int Mabonga = 1;
XC16
int _ _attribute_ _((address(0x100))) Mabonga = 1;