Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "translation unit" in C++?

Tags:

c++

I am reading at the time the "Effective C++" written by Scott 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 while programming with C++?

  3. Is it related to C++ only, or it can be used with other programming languages as well?

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

like image 619
Harry Avatar asked Jul 09 '09 20:07

Harry


2 Answers

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.

like image 59
JeffH Avatar answered Oct 06 '22 06:10

JeffH


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

http://msdn.microsoft.com/en-us/library/bxss3ska%28VS.80%29.aspx

like image 45
Ana Betts Avatar answered Oct 06 '22 06:10

Ana Betts