Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The curriculum

cmetal ships 62 exercises across 20 topics, ordered roughly from warm-up to the parts of C that bite in code review. Each is a real bug — the kind found in production C — never a fill-in-the-blanks template.

#TopicExercisesWhat you will learn
00Intro1Getting started, basic program structure
01Pointers2Decay, arithmetic, pointer-size pitfalls
02Memory3malloc/free, realloc, leaks, double-free
03Undefined Behavior4Signed overflow, sequence points, integer promotion, stack lifetimes
04Preprocessor1Stringify, token pasting, macro pitfalls
05UB Lab6Hands-on UB experiments with sanitizer feedback
06Strings3Safe concatenation, tokenizing, parsing
07Structs3Layout/padding, opaque types, linked lists
08Function Pointers3Callbacks, generic sort, dispatch tables
09Const Correctness3const parameters, pointer-to-const, immutable API
10Error Handling3Return codes, error propagation, error context
11Bitwise3Bit counting, packing/unpacking, bit tricks
12Encodings3Endianness, varints, bit packing — bytes on the wire
13Tagged Unions4Tag discipline, exhaustive dispatch, ownership, header-first polymorphism
14Hash Tables5FNV-1a, probing, tombstones, rehash on growth, interning
15Arenas3Bump allocation, alignment, chained growth, escape discipline
16Garbage Collection3Mark-sweep: reachability, cycles, sweep discipline, finalization
17NaN Boxing3IEEE-754 bit layout, legal punning, mask discipline, payload packing
18Bytecode Dispatch3Defensive stream decoding, refusable stacks, jump-table discipline
19Capstone3A binary format end to end: writing, validating, owning

How the topics build

The early topics (Pointers, Memory) establish the mental model that everything else depends on: what a pointer is, when an array decays into one, who owns a heap allocation and when it dies. Get these wrong and the rest of C is guesswork.

The middle topics turn that model against you. Undefined Behavior and the six-exercise UB Lab are where you deliberately trigger real UB — signed overflow, use-after-free, dangling pointers — and watch AddressSanitizer and UBSan catch it. The sanitizer report is the teaching material; the point isn't to avoid UB abstractly but to recognise what it looks like when a tool flags it.

The later foundations topics are about writing C other people can trust: Strings (the functions everyone gets wrong), Structs (layout, padding, opaque types), Function Pointers (callbacks and dispatch), Const Correctness (APIs that document their own immutability), Error Handling (codes that survive a real call chain), and Bitwise (the low-level idioms).

From topic 12 on, the implementation track applies all of it to the C found in interpreters, compilers, and binary formats: bytes on the wire (Encodings), data modelling under manual memory (Tagged Unions), Hash Tables built from scratch, Arenas as a lifetime strategy, a mark-sweep Garbage Collector with AddressSanitizer as the judge, the bit-level value representation of NaN Boxing, defensive Bytecode Dispatch, and a Capstone that serializes, validates and reloads a binary format end to end. The track follows the project-wide editorial rule stated in the roadmap: every exercise must be useful to someone who will never build an interpreter — an arena is a lifetime strategy, a varint decoder is any defensive parser — and no exercise requires code from an earlier chapter.

The UB Lab

The UB Lab (topic 05) is worth calling out. Most exercises ask you to fix a bug. The UB Lab asks you to observe one: you write the code that triggers a specific undefined behavior, run it under sanitizers, and read exactly how the tool reports it. Use-after-free across function boundaries, dangling stack pointers, integer promotion traps — the goal is fluency in what a sanitizer is telling you, which is a skill no book can hand you.

Seeing the list live

cmetal list shows every exercise with its status — solved, pending, or skipped because it requires a specific compiler. It is the authoritative, up-to-date view; this table is the map.

The curriculum is growing — where it's headed (concurrency, alignment and the machine model, long-lasting APIs, a C23 track) is in the roadmap.