Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 168
 2012 Microchip Technology Inc.
With any device, reserving memory in general purpose RAM (see 
Section 4.8.48 “--RAM: Adjust RAM Ranges”), or defining absolute variables in the 
middle of data banks (see Section 5.5.4 “Absolute Variables”), further restricts the 
contiguous memory in the data banks and may reduce the maximum size of objects 
you can define.
5.5.2.1.3
Changing the Default Non-Auto Variable Allocation
There are several ways in which non-auto variables can be located in locations other 
than those chosen by the compiler.
Variables can be placed in other memory spaces by the use of qualifiers. For example 
if you wish to place variables in the program memory space, then the const specifier 
should be used (see Section 5.4.7.1 “Const Type Qualifier”). The eeprom qualifier 
(see 5.4.8.5 “Eeprom Type Qualifier”) can be used to allocate variables to the 
EEPROM, if such memory exists on your target device.
If you wish to prevent variables from using one or more data memory locations so that 
these locations can be used for some other purpose, you are best reserving the mem-
ory using the memory adjust options. See Section 4.8.48 “--RAM: Adjust RAM 
Ranges”
 for information on how to do this.
If only a few non-auto variables are to be located at specific addresses in data space 
memory, then the variables can be made absolute. This allows individual variables to 
be explicitly positioned in memory at an absolute address. Absolute variables are 
described in Section 5.5.4 “Absolute Variables”. Once variables are made absolute, 
their address is hard coded in generated output code, they are no longer placed in a 
psect and do not follow the normal memory allocation procedure.
The psects in which the different categories of non-auto variables (the nv, bss and 
data
 psects described in Section 5.5.2.1 “Non-Auto Variable Allocation”) can be 
shifted as a whole by changing the default linker options. So, for example, you could 
move all the persistent variables. However, typically these psects can only be moved 
within the data bank in which they were allocated by default. See Section 5.10 “Main, 
Runtime Startup and Reset”
 for more information on changing the default linker 
options for psects. The code generate makes assumptions as to the location of these 
psects and if you move them to a location that breaks these assumptions, code may 
fail.
Non-auto can also be placed at specific positions by using the psect pragma, see 
Section 5.14.4.8 “The #pragma psect Directive”. The decision whether variables 
should be positioned this way or using absolute variables should be based on the 
location requirements.