2.1 Data and memory
How values are stored and manipulated at the level hardware cares about: fixed-width types and their traps, undefined behaviour, bit manipulation, pointers,…
Lessons
- Integers and data types · Fixed-width types, integer promotion, overflow and the signed/unsigned rules that bite.
- Undefined behaviour · Undefined, unspecified and implementation-defined behaviour, and why the optimiser makes UB dangerous.
- Bit manipulation · Masks, shifts, fields and the idioms every register access is built from.
- Pointers · Addresses, arithmetic, const, void pointers and object lifetime.
- Scope, linkage and storage duration · What static really means, declarations versus definitions, and where each variable lives.
- Arrays and strings · Decay, bounds, safe copying, and parsing and formatting without the heap.
- Structs, unions, alignment and byte order · Alignment and unaligned access, padding, packing, byte order, unions and bit-fields.
Project: Bike computer
The little screen on a handlebar, built with the right types and no undefined behaviour: speed and distance, ride statistics, a packed status byte, sensor records, text for a small screen, and a summary sent to the phone.