liveBook · Manning

Alignment

Memory alignment is the requirement that data be placed at an address satisfying the boundary constraints of its type or target architecture.

How 2 Manning books explain it

Modern C, Third Edition

Alignment is the implementation-defined requirement that an object or structure member begin at an address suitable for its type.

How it is used
Explains suitable object addresses in the C memory model and their role in structure layout and pointer conversions.
How deep it goes
Defines type alignment and demonstrates misaligned access with byte-offset pointer casts and a bus-error example.
Examples
Uses padded structure members and a byte-buffer overlay of complex values tested at progressively smaller offsets.
What you can do after
Diagnose misaligned pointer conversions by examining byte offsets and their effects on typed access.

Read how Modern C, Third Edition explains alignment →

Modern C

Alignment is the requirement that an object be stored at an address suitable for its type's access constraints.

How it is used
Constrains pointer-based access to objects within the C memory and object model.
How deep it goes
Defines permissible starting positions, demonstrates a crashing misaligned access, and stops short of broader hardware implementation details.
Examples
Demonstrates a complex double and byte-buffer union tested at offsets 16, 8, 4, 2, and 1.
What you can do after
Diagnose misaligned pointer access and request suitable storage alignment with alignas.

Read how Modern C explains alignment →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.