What is a "translation unit" in C++



I am reading at the time the "Effective C++" written by Meyers and came across the term "translation unit".

Could somebody please give me an explanation of:

1) What exactly it is

2) When should I consider using it when programming with C++

3) If it is related only to C++, or it can be used with other programming languages

I might already use it without knowing the term....

7/9/2009 8:05:19 PM

Accepted Answer

From here: (wayback machine link)

According to standard C++ (wayback machine link) : A translation unit is the basic unit of compilation in C++. It consists of the contents of a single source file, plus the contents of any header files directly or indirectly included by it, minus those lines that were ignored using conditional preprocessing statements.

A single translation unit can be compiled into an object file, library, or executable program.

The notion of a translation unit is most often mentioned in the contexts of the One Definition Rule, and templates.

9/27/2016 5:23:08 AM

A translation unit is for all intents and purposes a file (.c/.cpp), after it's finished including all of the header files.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow