FREE C, close to the metal LESSON · C, close to the metal

A pointer is permission with a lifetime

Objects, provenance, layout, and undefined behavior

An address-shaped number is not automatically a usable pointer.

A valid access depends on an object’s lifetime, the pointer’s relationship to that object, bounds, alignment, effective type, and the operation performed. `malloc` provides suitably aligned raw storage; your program establishes ownership and must eventually release it exactly once. The C abstract machine grants optimizers freedom when a program invokes undefined behavior, so “it worked in debug” is not evidence of a contract.

Track the object, not just the numeric address.

Undefined behavior is an optimizer boundary.

Out-of-bounds access, signed overflow, invalid shifts, unsequenced modifications, and lifetime violations let the implementation assume the forbidden case never occurs. Sanitizers add dynamic evidence, warnings expose suspicious constructs, and narrow interfaces reduce the state space—but the durable skill is reasoning from the language contract.

A sanitizer finds executions; the standard explains why the execution was invalid.
Practise this lesson free →