Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
Preprocessing
2012-2013 Microchip Technology Inc. DS50002071C-page 221
19.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, 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.
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 8.12 Variable Attributes and
Section 13.2.1 Function Specifiers.
TABLE 19-6: C18 PRAGMAS VS. ATTRIBUTES
TABLE 19-7: PICC18 PRAGMAS AND QUALIFIERS VS. ATTRIBUTES
EXAMPLE 19-1: SPECIFY AN UNINITIALIZED VARIABLE IN A USER SECTION
IN DATA MEMORY
where oldbss is the name of the psect (section) in which the variable would normally
be placed.
EXAMPLE 19-2: LOCATE THE VARIABLE MABONGA AT ADDRESS 0X100 IN
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;
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf