Microchip Technology SW006023-2N Data Sheet

Page of 238
Memory Allocation and Access
 2012 Microchip Technology Inc.
DS51686E-page 111
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 they are defined 
in begins execution. Any initialized static variables are initialized in the same way as 
other non-auto initialized objects by the runtime start-up code, see 
Section 3.5.2 “Peripheral Library Functions”. Static variables are located in the 
same sections as their non-static counterparts.
7.3.3
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 Section 6.6 “Structures 
and Unions”
. T
here are no theoretical limits as to how large these objects can be 
made.
7.3.4
Changing the Default Non-auto Variable Allocation
There are several ways in which non-auto variables can be located in locations other 
than the default.
Variables can be placed in other device 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 6.10.1 “Const Type Qualifier”).
If you wish to prevent all variables from using one or more data memory locations so 
that these locations can be used for some other purpose, you are best defining a vari-
able (or array) using the address attribute so that it consumes the memory space, see 
Section 6.12 “Variable Attributes”.
If only a few non-auto variables are to be located at specific addresses in data space 
memory, then the variables can be located using the address attribute. This attribute is 
described in Section 6.12 “Variable Attributes”.
7.3.5
Data Memory Allocation Macros 
Macros are provided for many commonly used attributes in order to enhance user code 
readability.
__section__(s)
Apply the 
section
 attribute with section name s.
__unique_section__
Apply the 
unique_section
 attribute.
__ramfunc__
Locate the attributed function in the RAM function code 
section.
__longramfunc__
Locate the attributed function in the RAM function code 
section and apply the 
longcall
 attribute.
__longcall__
Apply the 
longcall
 attribute.
__ISR(v,ipl)
Apply the 
interrupt
 attribute with priority level ipl 
and the 
vector
 attribute with vector number v.
__ISR_AT_VECTOR(v,ipl)
Apply the 
interrupt
 attribute with priority level ipl 
and the 
at_vector
 attribute with vector number v.
__ISR_SINGLE__ 
Specifies a function as an Interrupt Service Routine in 
single-vector mode. This places a jump at the 
single-vector location to the interrupt handler.
__ISR_SINGLE_AT_VECTOR_
Places the entire single-vector interrupt handler at the 
vector 0 location. When used, ensure that the vector 
spacing is set to accommodate the size of the handler.