9.10 Variable Attributes

The MPLAB XC-DSC C Compiler uses attributes to indicate memory allocation, type and other configuration for variables, structure members and types. Other attributes are available for functions, and these are described in the 14.1.2 Function Attributes section. Qualifiers are used independently to attributes (see the 9.9 Compiler-Specific Type Qualifiers section). They only indicate how objects are accessed, but must be used where necessary to ensure correct code operation.

The compiler keyword __attribute__ allows you to specify the attributes of objects. This keyword is followed by an attribute specification inside double parentheses. The attributes below are currently supported for variables.

You may also specify attributes with __ (double underscore) preceding and following each keyword (e.g., __aligned__ instead of aligned). This allows you to use them in header files without being concerned about a possible macro of the same name.

To specify multiple attributes, separate them by commas within the double parentheses, for example:

__attribute__ ((aligned (16), packed)).

Note: It is important to use variable attributes consistently throughout a project. For example, if a variable is defined in file A with the far attribute and declared extern in file B without far, then a link error may result.