IT lexicon › Programming › ODR

ODR One Definition Rule

Programming På svenska → Updated: 2026-07-29

The rule that each thing may be defined exactly once in a program, and that whatever may be defined more than once must be defined identically everywhere.

A class or an inline function may appear in several translation units, but every definition must consist of the same tokens and mean the same thing. The unpleasant part is the standard's wording: violations are ill-formed, no diagnostic required. The compiler sees one file at a time and the linker sees only mangled names, so when two files define the same class differently — typically because a #define or a packing pragma differed between two libraries — the linker silently picks one and discards the other. The result is a program that works until somebody changes the link order. Tooling does exist: ASan has a check for it, as do lld and gold.

← Back to the lexicon