Microchip Technology SW006022-2 Data Sheet

Page of 338
MPLAB
®
 XC16 C Compiler User’s Guide
DS52071B-page 104
 2012 Microchip Technology Inc.
6.10
COMPILER-SPECIFIC TYPE QUALIFIERS
The MPLAB XC16 C Compiler supports special type qualifiers, all of which allow the 
user to control how variables are accessed.
6.10.1
__psv__ Type Qualifier
The __psv__ qualifier can be applied to variables or pointer targets that have been 
allocated to the program memory space. It indicates how the variable or pointer targets 
will be accessed/read. Allocation of variables to the program memory space is a sepa-
rate process and is made using the space attribute, so this qualifier is often used in 
conjunction with that attribute when the variable is defined. For example:
__psv__ unsigned int __attribute__((space(psv))) myPSVvar = 0x1234;
__psv__ char * myPSVpointer;
The pointer in this example does not use the space attribute as it is located in data 
memory, but the qualifier indicates how the pointer targets are to be accessed. For 
more information on the space attribute and how to allocate variables to the Flash 
memory, seSection 6.11 “Variable Attributes”. For basic information on the 
memory layout and how program memory is accessed by the device, see 
Section 7.2 “Address Spaces”.
When variables qualified as __psv__ are read, the compiler will manage the selection 
of the program memory page visible in the data memory window. This means that you 
do not need to adjust the PSVPAG SFR explicitly in your source code, but the gener-
ated code may be slightly less efficient than that produced if this window was managed 
by hand.
The compiler will assume that any object or pointer target qualified with __psv__ will 
wholly fit within a single PSV page. Such is the case for objects allocated memory using 
the psv or auto_psv space attribute. If this is not the case, then you should use the 
__prog__
appropriate space attribute.
6.10.2
__prog__ Type Qualifier
The __prog__ qualifier is similar to the __psv__ qualifier (see 
Section 6.10.1 “__psv__ Type Qualifier”), but indicates to the compiler that the qual-
ified variable or pointer target may straddle PSV pages. As a result, the compiler will 
generate code so these qualified objects can be read correctly, regardless of which 
page they are allocated to. This code may be longer than that to access variables or 
pointer targets which are qualified __psv__. For example:
__prog__ unsigned int __attribute__((space(prog))) myPROGvar = 0x1234;
__prog__ char * myPROGpointer;
The pointer in this example does not use the space attribute as the it is located in data 
memory, but the qualifier indicates how the pointer targets are to be accessed. For 
more information on the space attribute and how to allocate variables to the Flash 
memory, seSection 6.11 “Variable Attributes”. And, seSection 7.2 “Address 
Spaces”
 
for basic information on the memory layout and how program memory is 
accessed by the device.