4.38 Unaligned pointers in C and C++ code

If you want to define a pointer that can point to a word at any address, you must specify the __packed qualifier.

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.
For example, to specify an unaligned pointer:
__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.
Related concepts
4.39 Unaligned Load Register (LDR) instructions generated by the compiler
Related reference
9.12 __packed
7.164 --unaligned_access, --no_unaligned_access
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.