4.4.11 Packing Objects
The __pack
specifier can 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 cannot pad structures with alignment gaps for some devices, and use of this specifier for such devices is ignored.
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;
Differences
The __pack
specifier is a new CCI specifier that is available with MPLAB
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 structure member was not aligned with a memory gap.
Migration to the CCI
No migration is required for MPLAB XC8.
For 16- and 32-bit compilers, change any occurrence of the packed
attribute, for example, from:
struct DOT
{
char a;
int x[2] __attribute__ ((packed));
};
to:
struct DOT
{
char a;
__pack int x[2];
};
Alternatively, you can pack the entire structure, if required.
Caveats
None.