Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 Manuel D’Utilisation
Codes de produits
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 174
2012 Microchip Technology Inc.
5.5.3.1
SIZE LIMITATIONS OF CONST VARIABLES
Arrays of any type (including arrays of aggregate types) can be qualified const and
placed in the program memory. So too can structure and union aggregate types, see
5.4.4 “Structures and Unions”. These objects can often become large in size and
may affect memory allocation.
placed in the program memory. So too can structure and union aggregate types, see
5.4.4 “Structures and Unions”. These objects can often become large in size and
may affect memory allocation.
For baseline PIC devices, the maximum size of a single const object is 255 bytes.
However, you can define as many const objects as required provided the total size
does not exceed the available program memory size of the device. Note that as well as
other program code, there is also code required to be able to access const-qualified
data in the program memory space. Thus, you may need additional program memory
space over the size of the object itself. This additional code to access the const data
is only included once, regardless of the amount or number of const-qualified objects.
However, you can define as many const objects as required provided the total size
does not exceed the available program memory size of the device. Note that as well as
other program code, there is also code required to be able to access const-qualified
data in the program memory space. Thus, you may need additional program memory
space over the size of the object itself. This additional code to access the const data
is only included once, regardless of the amount or number of const-qualified objects.
For all other 8-bit devices, the maximum size of a const-qualified object is limited only
by the available program memory. These devices also use additional code that
accesses the const data. PIC18 devices need additional code each time an object is
accessed, but this is typically small. The mid-range devices include a larger routine, but
this code is also only included once, regardless of the amount or number of
const
by the available program memory. These devices also use additional code that
accesses the const data. PIC18 devices need additional code each time an object is
accessed, but this is typically small. The mid-range devices include a larger routine, but
this code is also only included once, regardless of the amount or number of
const
-qualified objects.
5.5.3.2
CHANGING THE DEFAULT ALLOCATION
If you only intend to prevent all variables from using one or more program memory loca-
tions so that you can use those locations for some other purpose, you are best reserv-
ing the memory using the memory adjust options. See Section 4.8.49 “--ROM: Adjust
ROM Ranges” for information on how to do this.
tions so that you can use those locations for some other purpose, you are best reserv-
ing the memory using the memory adjust options. See Section 4.8.49 “--ROM: Adjust
ROM Ranges” for information on how to do this.
If only a few non-auto const variables are to be located at specific addresses in pro-
gram space memory, then the variables can be made absolute. This allows individual
variables to be explicitly positioned in memory at an absolute address. Absolute vari-
ables 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.
gram space memory, then the variables can be made absolute. This allows individual
variables to be explicitly positioned in memory at an absolute address. Absolute vari-
ables 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 const variables can be
shifted as a whole by changing the default linker options. However, there are limitations
in where these psects can be moved to. See Section 5.10 “Main, Runtime Startup
and Reset” for more information on changing the default linker options for these
psects.
shifted as a whole by changing the default linker options. However, there are limitations
in where these psects can be moved to. See Section 5.10 “Main, Runtime Startup
and Reset” for more information on changing the default linker options for these
psects.
Variables in program memory can also be placed at specific positions by using the
psect
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.
based on the location requirements.