7.4.8 Alignment of Objects

The __align(alignment) specifier can be used to indicate that variables must be aligned on a memory address that is a multiple of the alignment specified. The alignment term must be a power of 2. Positive values request that the object’s start address be aligned.

Use the native keywords discussed in the Differences section to look up information on the semantics of this specifier.

Example

The following shows variables qualified using __align() to ensure they end on an address that is a multiple of 8, and start on an address that is a multiple of 2, respectively.
__align(-8) int spacer;
__align(2) char coeffs[6];

Differences

The MPLAB XC16, XC-DSC and XC32 compilers have used the aligned attribute with variables. This has also been true when targeting AVR MCUs with MPLAB XC8 An alignment feature has never been available for PIC devices when using the MPLAB XC8 compiler.

Migration to the CCI

When building for AVR MCUs with the MPLAB XC8 compiler or when using any other compiler, change any occurrence of the aligned attribute to the __align specifier, for example, from:

char __attribute__((aligned(4)))mode;

to:

__align(4) char mode;

Caveats

This feature is not needed nor implemented when targeting PIC devices using MPLAB XC8.

When targeting PIC32C/SAM devices with MPLAB XC32 only positive alignment values are supported.