Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the terms "source file" and "translation unit"?

What's the difference between source file and translation unit?

like image 244
user336359 Avatar asked May 08 '10 20:05

user336359


People also ask

What is meant by translation unit?

In the field of translation, a translation unit is a segment of a text which the translator treats as a single cognitive unit for the purposes of establishing an equivalence. It may be a single word, a phrase, one or more sentences, or even a larger unit.

What's a translation unit in C?

In C and C++ programming language terminology, a translation unit (or more casually a compilation unit) is the ultimate input to a C or C++ compiler from which an object file is generated.

What does translation unit mean in C++?

A translation unit is the basic unit of compilation in C++. This unit is made up of the contents of a single source file after it passes through preprocessing. It contains included any header files without blocks that are ignored using conditional preprocessing statements like ifdef, ifndef, etc.


2 Answers

From the C++ Standard:

A source file together with all the headers and source files included via the preprocessing directive #include less any source line skipped by any of the conditional inclusion preprocessing directives is called a translation unit.

like image 198
There is nothing we can do Avatar answered Sep 22 '22 14:09

There is nothing we can do


A "translation unit" is a source file plus any headers or other source files it #includes, plus any files that THEY include, and so on. A source file is just that...one source file.

If it helps any, think of the source file as the "before" the preprocessor runs, and the translation unit as "after". Or, think of it as the preprocessor's job to turn a source file into a translation unit.

like image 36
cHao Avatar answered Sep 18 '22 14:09

cHao