liveBook · Manning

Translation unit

As explained in Modern C

A translation unit is the source code produced after preprocessing one C source file together with its included material and presented to the compiler.

Consider a source file containing `#include "toto.h"` and a declaration such as `toto* toto_init(toto*);`. After preprocessing, that source file and its included material form one translation unit: the unit presented to the compiler. A function definition is visible for inlining only when the caller and definition occur in the same translation unit. section 15.1

Header definition and one instantiation

An inline definition can live in a header, while a matching non-defining declaration is instantiated in exactly one translation unit. This arrangement makes the definition available where needed without treating every inclusion as another definition.

TAKEAWAY: A translation unit is a compiler-facing boundary created from one preprocessed C source file and its included material. It affects what definitions the compiler can see together, enabling inlining and further optimization when caller and callee share that boundary. section 15.1

How Modern C covers it

How deep it goes
Explains compiler visibility and optimization consequences, without detailing preprocessing phases or linkage rules.
Examples
Uses an inline definition in a header and a matching declaration instantiated in exactly one translation unit.
What it assumes
Assumes familiarity with C functions and declarations while showing how definitions become visible to the compiler.
What you can do after
Understand how source inclusion and definition visibility determine the compiler's translation-unit view.
How it connects
Connects translation units with functions, inline functions, headers, preprocessing, and compiler optimization.

Also explained in

Compare how 2 books explain translation unit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.