Microchip Technology SW006023-2 Data Sheet

Page of 238
Supported Data Types and Variables
 2012 Microchip Technology Inc.
DS51686E-page 105
A C/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:
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.
6.11
COMPILER-SPECIFIC QUALIFIERS
There are no non-standard qualifiers implemented in MPLAB XC32 C/C++ Compiler. 
Attributes are used to control variables and functions.
6.12
VARIABLE ATTRIBUTES
The compiler keyword attribute allows you to specify special attributes of variables 
or structure fields. This keyword is followed by an attribute specification inside double 
parentheses.
To specify multiple attributes, separate them by commas within the double 
parentheses, for example:
 
attribute ((aligned (16), packed))
.
address (addr)
Specify an absolute virtual address for the variable. This attribute can be used in 
conjunction with a section attribute. For data variables, the address is typically in the 
range [0xA0000000,0xA00FFFFC], as defined in the linker script as the 
‘kseg1_data_mem’ region. This attribute can be used to start a group of variables at a 
specific address:
  int foo __attribute__((section(“mysection”),address(0xA0001000)));
  int bar __attribute__((section(“mysection”)));
  int baz __attribute__((section(“mysection”)));
Keep in mind that the compiler performs no error checking on the specified address. 
The section will be located at the specified address regardless of the memory-region 
ranges listed in the linker script or the actual ranges on the target device. This 
application code is responsible for ensuring that the address is valid for the target 
device and application.
Also, be aware that variables attributed with an absolute address are not accessed via 
GP-relative addressing. This means that they may be more expensive to access than 
non-address attributed variables.
In addition, to make effective use of absolute sections and the new best-fit allocator, 
standard program-memory and data-memory sections should not be mapped in the 
linker script. The built-in linker script does not map most standard sections such as the 
.text
, .data, .bss, or .ramfunc section. By not mapping these sections in the 
linker script, we allow these sections to be allocated using the best-fit allocator rather 
than the sequential allocator. Sections that are unmapped in the linker script can flow 
around absolute sections whereas sections that are linker-script mapped are grouped 
together and allocated sequentially, potentially causing conflicts with absolute sections.
Note:
It is important to use variable attributes consistently throughout a project. 
For example, if a variable is defined in file A with the aligned attribute, and 
declared extern in file B without aligned, then a link error may result.