Keil Logo

C166: Packing Bytes in Unions and Structures


Information in this article applies to:

  • C166 Version 4.02 and later

SYMPTOMS

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?

CAUSE

The compiler does this to optimize memory accesses for the C166 family of processors.

RESOLUTION

The compiler directive PACK() instructs the compiler to declare memory for the union or structure without the pad bytes. Just insert the line:

#pragma PACK(1)

in the file where the union or structure is declared and memory will be accessed accordingly.

MORE INFORMATION

  • Refer to PACK in the C166 User's Guide.

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.


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.