ARM Technical Support Knowledge Articles

PACKING BYTES IN UNIONS AND STRUCTURES

Applies to: C166 C Compiler

Answer


Information in this article applies to:


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

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.

Article last edited on: 2005-08-03 12:54:27

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential