Microchip Technology SW006022-1N Ficha De Dados
MPLAB
®
XC16 C Compiler User’s Guide
DS52071B-page 118
2012 Microchip Technology Inc.
The extensions presented here allow the definition of a variable as being a ‘managed’
PSV variable. This means that the compiler will manipulate both the offset (within a
PSV page) and the page itself. As a consequence, data pointers must be 32 bits. The
compiler will probably generate more instructions than the single PSV page model, but
that is the price being paid to buy more flexibility and shorter coding time to access
larger amounts of data in Flash.
PSV variable. This means that the compiler will manipulate both the offset (within a
PSV page) and the page itself. As a consequence, data pointers must be 32 bits. The
compiler will probably generate more instructions than the single PSV page model, but
that is the price being paid to buy more flexibility and shorter coding time to access
larger amounts of data in Flash.
7.3
VARIABLES IN DATA SPACE MEMORY
Most variables are ultimately positioned into the data space memory. The exceptions
are non-auto variables which are qualified as const and may be placed in the pro-
gram memory space.
are non-auto variables which are qualified as const and may be placed in the pro-
gram memory space.
Due to the fundamentally different way in which auto variables and non-auto vari-
ables are allocated memory, they are discussed separately. To use the C language ter-
minology, these two groups of variables are those with ‘automatic storage duration’ and
those with ‘permanent storage duration’, respectively.
ables are allocated memory, they are discussed separately. To use the C language ter-
minology, these two groups of variables are those with ‘automatic storage duration’ and
those with ‘permanent storage duration’, respectively.
The terms “local” and “global” are commonly used to describe variables, but are not
ones defined by the language standard. The term “local variable” is often taken to mean
a variable which has scope inside a function, and “global variable” is one which has
scope throughout the entire program. However, the C language has three common
scopes: block, file (i.e. internal linkage) and program (i.e. external linkage). So using
only two terms to describe these can be confusing.
ones defined by the language standard. The term “local variable” is often taken to mean
a variable which has scope inside a function, and “global variable” is one which has
scope throughout the entire program. However, the C language has three common
scopes: block, file (i.e. internal linkage) and program (i.e. external linkage). So using
only two terms to describe these can be confusing.
For example, a static variable defined outside a function has scope only in that file,
so it is not globally accessible, but it can be accessed by more than one function inside
that file, so it is not local to any one function either.
so it is not globally accessible, but it can be accessed by more than one function inside
that file, so it is not local to any one function either.
In terms of memory allocation, variables are allocated space based on whether it is an
auto
auto
or not; hence the grouping in the following sections.
7.3.1
Non-Auto Variable Allocation and Access
Non-auto (static and external) variables have permanent storage duration and
are located by the compiler into the data space memory. The compiler will also allocate
non-auto const-qualified variables (see Section 6.9.1 “Const Type Qualifier”) into
the data space memory if the constants-in-data memory model is selected; otherwise,
they are located in program memory.
are located by the compiler into the data space memory. The compiler will also allocate
non-auto const-qualified variables (see Section 6.9.1 “Const Type Qualifier”) into
the data space memory if the constants-in-data memory model is selected; otherwise,
they are located in program memory.
7.3.1.1
DEFAULT ALLOCATION OF NON-AUTO VARIABLES
The compiler considers several categories of static and external variable, which all
relate to the value the variable should contain at the time the program begins, that is,
those that should be cleared at program startup (uninitialized variables), and those that
should hold a non-zero value (initialized variables), and those that should not be altered
at all at program startup (persistent variables). Those objects qualified as const are
usually assigned an initial value since they are read-only. If they are not assigned an
initial value, they are grouped with the other uninitialized variables.
relate to the value the variable should contain at the time the program begins, that is,
those that should be cleared at program startup (uninitialized variables), and those that
should hold a non-zero value (initialized variables), and those that should not be altered
at all at program startup (persistent variables). Those objects qualified as const are
usually assigned an initial value since they are read-only. If they are not assigned an
initial value, they are grouped with the other uninitialized variables.
Data placed in RAM may be initialized at startup by copying initialized values from pro-
gram memory.
gram memory.