By default, the compiler expects conventional C and C++ pointers
to point to naturally aligned words in memory because this enables
the compiler to generate more efficient code.
If you want to define a pointer that can point to a word at
any address, you must specify the __packed qualifier
when defining the pointer. For example:
__packed int *pi; // pointer to unaligned int
When a pointer is declared as __packed,
the compiler generates code that correctly accesses the dereferenced
value of the pointer, regardless of its alignment. The generated
code consists of a sequence of byte accesses, or variable alignment-dependent
shifting and masking instructions, rather than a simple LDR instruction.
Consequently, declaring a pointer as __packed incurs
a performance and code size penalty.
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.