Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 162
2012 Microchip Technology Inc.
A C statement that consists only of a volatile variable’s name will produce code that
reads the variable’s memory location and discards the result. For example the entire
statement:
reads the variable’s memory location and discards the result. For example the entire
statement:
PORTB;
will produce assembly code the reads PORTB, but does nothing with this value. This is
useful for some peripheral registers that require reading to reset the state of interrupt
flags. Normally such a statement is not encoded as it has no effect.
useful for some peripheral registers that require reading to reset the state of interrupt
flags. Normally such a statement is not encoded as it has no effect.
Some variables are treated as being volatile even though they may not be qualified
in the source code. See Section 5.12.3.4 “Undefined Symbols” if you have assem-
bly code in your project.
in the source code. See Section 5.12.3.4 “Undefined Symbols” if you have assem-
bly code in your project.
5.4.8
Special Type Qualifiers
The MPLAB XC8 C Compiler supports special type qualifiers to allow the user to control
placement of static and extern class variables into particular address spaces.
placement of static and extern class variables into particular address spaces.
5.4.8.1
PERSISTENT TYPE QUALIFIER
By default, any C variables that are not explicitly initialized are cleared on startup. This
is consistent with the definition of the C language. However, there are occasions where
it is desired for some data to be preserved across a Reset.
is consistent with the definition of the C language. However, there are occasions where
it is desired for some data to be preserved across a Reset.
The persistent type qualifier is used to qualify variables that should not be cleared
by the runtime startup code.
by the runtime startup code.
In addition, any persistent variables will be stored in a different area of memory to
other variables. Different psects are used to hold these objects. See
5.15.2 “Compiler-Generated Psects” for more information.
other variables. Different psects are used to hold these objects. See
5.15.2 “Compiler-Generated Psects” for more information.
This type qualifier may not be used on variables of class auto; however, statically
defined local variables may be qualified persistent. For example, you should write:
defined local variables may be qualified persistent. For example, you should write:
void test(void)
{
static persistent int intvar; /* must be static */
// ...
}
If the xc8 option, --STRICT is used, this type qualifier is changed to __persistent.
5.4.8.2
NEAR TYPE QUALIFIER
Some of the 8-bit PIC architectures implement data memory which can be always
accessed regardless of the currently selected bank. This common memory can be
used to reduce code size and execution times as the bank selection instructions that
are normally required to access data in banked memory are not required when access-
ing the common memory. PIC18 devices refer to this memory as the access bank mem-
ory. Mid-range and baseline devices have very small amounts of this memory, if it is
present at all. PIC18 devices have substantially more common memory, but the amount
differs between devices. See your device data sheet for more information.
accessed regardless of the currently selected bank. This common memory can be
used to reduce code size and execution times as the bank selection instructions that
are normally required to access data in banked memory are not required when access-
ing the common memory. PIC18 devices refer to this memory as the access bank mem-
ory. Mid-range and baseline devices have very small amounts of this memory, if it is
present at all. PIC18 devices have substantially more common memory, but the amount
differs between devices. See your device data sheet for more information.
The near type qualifier can be used to place non-auto variables in common memory.
The compiler automatically uses the common memory for frequently accessed
user-defined variables so this qualifier would only be needed for special memory place-
ment of objects, for example if C variables are accessed in hand-written assembly code
that assumes that they are located in this memory.
user-defined variables so this qualifier would only be needed for special memory place-
ment of objects, for example if C variables are accessed in hand-written assembly code
that assumes that they are located in this memory.