In C++ programming, a translation unit refers to the basic unit of compilation. It can be understood as a single source file, such as a .c
or .cpp
file, along with all the header files it includes, whether directly or indirectly. The header files typically have extensions like .h
or .hpp
. After the preprocessing stage, the content of this source file—now a translation unit—contains all the included header files and excludes any parts of the code that have been ignored due to conditional preprocessing directives like #ifdef
and #ifndef
. Each translation unit is then compiled independently by the compiler to produce an object file.