Provides functions for safe unaligned memory accesses. More...
Provides functions for safe unaligned memory accesses.
This header provides functions to read values from pointers that are not necessarily aligned to the type's alignment requirements.
E.g.,
uint16_t *foo = 0x123; printf("%u\n", *foo);
... might cause an unaligned access, if uint16_t
is usually aligned at 2-byte-boundaries, as foo has an odd address.
The current implementation casts a pointer to a packed struct, which forces the compiler to deal with possibly unalignedness. Idea taken from linux kernel sources.
Files | |
file | unaligned.h |
Unaligned but safe memory access functions. | |
Data Structures | |
struct | uint16_una_t |
Unaligned access helper struct (uint16_t version) More... | |
Functions | |
static uint16_t | unaligned_get_u16 (const void *ptr) |
Get uint16_t from possibly unaligned pointer. More... | |
|
inlinestatic |
Get uint16_t from possibly unaligned pointer.
[in] | ptr | pointer to read from |
ptr
Definition at line 58 of file unaligned.h.