What's the difference between source file and 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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With