# Vision
**cmetal aims to be a practical path from "I know the syntax of C" to "I can
defend my C in a code review". A growing part of that path uses the problems
of language implementations and binary formats.**
Most C courses stop when a program compiles. The difficult topics of the
language come after that point: undefined behavior, aliasing, the lifetime of
memory, the use of `const`, and error handling across several function calls.
Books explain these topics. cmetal lets a learner practice them and checks
the result, as rustlings does for Rust.
## Where we are
cmetal has 62 exercises across 20 topics, in two parts. The foundations
(topics 00 to 11) cover advanced C in general: the intro, pointers, memory,
undefined behavior and the UB Lab, the preprocessor, strings, structs,
function pointers, const, error handling and bitwise operations. The
implementation track (topics 12 to 19) applies them to the C of language
implementations and binary formats: encodings, tagged unions, hash tables,
arenas, a mark-and-sweep garbage collector, NaN boxing, bytecode dispatch,
and a capstone that writes, validates and loads a bytecode chunk with a magic
number, a version, a constant pool and a code stream.
The tool around the exercises has a watch mode with hints, verification with
the sanitizers, and solutions that it shows only after the learner solves an
exercise. The binary contains the curriculum. `cmetal init` creates a
workspace without a git clone, and `cmetal update` brings new exercises
without overwriting the work of the learner. One version tag publishes every
way to install: Homebrew, prebuilt archives and crates.io
(`cargo install cmetal`).
## Design principles
Every change must respect these rules:
1. **The learner fixes code.** Every exercise is a program with a defect of a
kind that occurs in production C. No exercise is a template with blanks to
fill.
2. **Every exercise fails as shipped, and every solution passes.** CI checks
this rule with `scripts/check_exercises.py`. An exercise that passes as
shipped teaches nothing.
3. **The feedback is fast.** The learner saves the file and sees the result.
The compiler errors, the test failures and the sanitizer reports are the
teaching material.
4. **No solution appears by accident.** A solution stays hidden until the
learner solves the exercise. Then cmetal shows it next to the learner's
own fix.
5. **C11 and the usual toolchains.** cmetal uses gcc and clang with ASan and
UBSan. It has no runtime of its own and no framework.
6. **The clone of the learner stays clean.** The learner works in directories
that git ignores, and learning never changes the repository.
## Where we want to go
### The direction: the C of language implementations
cmetal has an implementation track about the C of interpreters, compilers
and binary formats. That domain covers much of advanced C: tagged unions,
hash tables, arenas, garbage collectors and bytecode. All of it is C11 in
user space, where the sanitizers give direct feedback. The track also fills a
known gap: the standard book on the subject tells readers who are not yet
comfortable with C to read an introductory book first.
The general curriculum of advanced C stays. It is the foundation of the
implementation track.
One editorial rule keeps cmetal a C trainer and not an interpreter tutorial:
**every exercise must be useful to someone who will never build an
interpreter**. Byte-order-safe I/O belongs in every protocol. A varint
decoder is a parser of input that can be damaged. An arena is a way to manage
lifetimes. A garbage collector is a traversal of a graph of owned memory.
Every exercise stands alone: none needs the code of another exercise.
### Near term: deepen the foundations
The first version of the implementation track is complete: topics 12 to 19
are released. The next work is on the foundations:
- **More exercises for the short topics.** Intro and Preprocessor have one
exercise each, Pointers has two, and several topics have three. Each topic
should have 3 to 5.
- **More UB Lab scenarios**: use after free across functions, double free,
misaligned access.
- **Notes on how to read a sanitizer report**, attached to the hints of each
exercise.
### Mid term: the chapters of advanced C that are missing
- **Concurrency:** C11 `<threads.h>`, atomics, and data races that
ThreadSanitizer reports.
- **The machine model:** alignment, padding, `restrict` and `volatile`, and
what the optimizer assumes. Topic 12 already covers byte order.
- **Long-lived APIs:** opaque handles, ownership conventions and the basics
of ABI stability.
- **Difficulty ratings and optional tracks**, so that a learner can follow a
systems track or an embedded track through the same exercises.
### Long term
- **A C23 track**, when compiler support is mature (`nullptr`, `constexpr`,
checked arithmetic).
- **Exercises from the community.** A contributor should be able to add an
exercise in about 30 minutes, with the invariant checker as the only gate.
- **Hints in other languages.** The code stays in English.
## Non-goals
- cmetal does not teach the syntax of C. A learner starts with an
introductory course and then comes to cmetal.
- cmetal does not teach compiler theory. Other books cover parsing
algorithms and type systems. cmetal teaches the C that those books assume.
- cmetal does not teach C++, which is a different language.
- cmetal is not an IDE, a build system or a general C course. It does one
thing: practice on advanced C.
## How to help
Choose one of the topics above, write a program with a defect, its tests and
its fix, and read [CONTRIBUTING.md](CONTRIBUTING.md). The exercise is ready
for review when `scripts/check_exercises.py` passes.