C166: Packing Bytes in Unions and Structures
Information in this article applies to:
When structures or unions are defined where chars and ints are intermixed, the compiler pads the declaration with blank bytes to word align the char in memory. Why?
The compiler does this to optimize memory accesses for the C166 family of processors.
The compiler directive PACK() instructs the compiler to declare memory for the union or structure without the pad bytes. Just insert the line:
in the file where the union or structure is declared and memory will be accessed accordingly.
Note: By not having the pad bytes added to the char elements code generated to access them will be much larger and slower than code written for word aligned accesses.
The following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Tuesday, November 3, 2020
of your data.