unaligned memory access methods

Provides functions for safe unaligned memory accesses. More...

Detailed Description

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...
 

Function Documentation

◆ unaligned_get_u16()

static uint16_t unaligned_get_u16 ( const void *  ptr)
inlinestatic

Get uint16_t from possibly unaligned pointer.

Parameters
[in]ptrpointer to read from
Returns
value read from ptr

Definition at line 58 of file unaligned.h.