Microchip Technology SW006022-2N Data Sheet

Page of 338
MPLAB
®
 XC16 C Compiler User’s Guide
DS52071B-page 42
 2012 Microchip Technology Inc.
2.5.11
Packing Objects
The __pack specifier may be used to indicate that structures should not use memory 
gaps to align structure members, or that individual structure members should not be 
aligned.
Use the native keywords discussed in the Differences section to look up information on 
the semantics of this specifier.
Some compilers may not pad structures with alignment gaps for some devices and use 
of this specifier for such devices will be ignored.
2.5.11.1
EXAMPLE
The following shows a structure qualified using __pack as well as a structure where 
one member has been explicitly packed.
__pack struct DATAPOINT {
unsigned char type;
int value;
} x-point;
struct LINETYPE {
unsigned char type;
__pack int start;
long total;
} line;
2.5.11.2
DIFFERENCES
The __pack specifier is a new CCI specifier available with XC8. This specifier has no 
apparent effect since the device memory is byte addressable for all data objects.
 The 16- and 32-bit compilers have used the packed attribute to indicate that a struc-
ture member was not aligned with a memory gap.
2.5.11.3
MIGRATION TO THE CCI
No migration is required for XC8.
For 16- and 32-bit compilers, change any occurrence of the packed attribute, as in the 
following example:
struct DOT
{
char a;
int x[2] __attribute__ ((packed));
};
to:
struct DOT
{
char a;
__pack int x[2];
};
Alternatively, you may pack the entire structure, if required.
2.5.11.4
CAVEATS
None.