Jump to content
  • Advertisement
Sign in to follow this  
fpsgamer

In simple terms: What is a translation unit in C/C++?

This topic is 3920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In simple terms: What is a translation unit in C/C++? Is it the same as an object file? Also is a compilation unit the same thing?

Share this post


Link to post
Share on other sites
Advertisement
Making an executable program consists of a translation phase and a linkage phase . During translation, each individual source file is compiled into an object file. The process of translation involves the preprocessor that brings in any #include'd files and the result of preprocessing the source file is the translation unit. The object files are tied together by the linker into a single, complete executable program. The linker also brings together any C++ Standard libraries as well as any personal libraries that may be needed.

The unit of compilation, or compilation unit has to do with the way that you organize your code for the compiler. For C++ programs, this is a .cpp file, normally. So, by this definition, the translation unit and compilation unit are technically not the same, but are closely related.

Stroustrup suggests that the compilation unit is what the programmer sees, whereas the translation unit is what the compiler sees.

Object files are binary and are the result of compiling translation units. The object files are linked at the final stage as stated above to form the final executable.

--random

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!