Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 167
Note that the data psect used to hold initialized variables is the psect that holds the 
RAM variables themselves. There is a corresponding psect (called idata) that is 
placed into program memory (so it is non-volatile) and which is used to hold the initial 
values that are copied to the RAM variables by the runtime startup code.
All non-auto variables, except for static variables, discussed in 
Section 5.5.2.1.1 “Static Variables”, always use their lexical name with a leading 
underscore character as the assembly identifier used for this object. See 
Section 5.12.3.1 “Equivalent Assembly Symbols” for more information on the 
mapping between C- and assembly-domain symbols.
5.5.2.1.1
Static Variables
All static variables have permanent storage duration, even those defined inside a 
function which are “local static” variables. Local static variables only have scope in 
the function or block in which they are defined, but unlike auto variables, their memory 
is reserved for the entire duration of the program. Thus they are allocated memory like 
other non-auto variables.
Static variables may be accessed by other functions via pointers since they have 
permanent duration.
Variables which are static are guaranteed to retain their value between calls to a 
function, unless explicitly modified via a pointer.
Variables which are static and which are initialized only have their initial value 
assigned once during the program’s execution. Thus, they may be preferable over ini-
tialized auto objects which are assigned a value every time the block in they are 
defined begins execution. Any initialized static variables are initialized in the same 
way as other non-auto initialized objects by the runtime startup code, see 
Section 4.4.2 “Startup and Initialization”.
The assembly symbols used to access static objects in assembly code are discussed 
in Section 5.12.3.1 “Equivalent Assembly Symbols”.
5.5.2.1.2
Non-Auto Variable Size Limits
Arrays of any type (including arrays of aggregate types) are fully supported by the com-
piler. So too are the structure and union aggregate types, see 5.4.4 “Structures and 
Unions”
. T
hese objects can often become large in size and may affect memory allo-
cation.
When compiling for enhanced mid-range PIC devices, the size of an object (array or 
aggregate object) is typically limited only by the total available data memory. Single 
objects that will not fit into any of the available general purpose RAM ranges will be allo-
cated memory in several RAM banks and accessed using the device’s linear GPR 
(general purpose RAM).
Note that the special function registers (which reside in the data memory space) or 
memory reservations in general purpose RAM may prevent objects from being allo-
cated contiguous memory in the one bank. In this case objects that are smaller than 
the size of a RAM bank may also be allocated across multi-banks. The generated code 
to access multi-bank objects will always be slower and the associated code size will be 
larger than for objects fully contained within a single RAM bank.
When compiling for PIC18 devices, the size of an object is also typically limited only by 
the data memory available. Objects can span several data banks.
On baseline and other mid-range devices, arrays and structures are limited to the max-
imum size of the available GPR memory in each RAM bank, not the total amount of 
memory remaining. An error will result if an array is defined which is larger than this 
size.