I was convinced that a translation unit is a .cpp
file (or, to avoid referring to an extension, a file you would feed to `g++ -c theTranslationUnit.cpp -o whatever.o) once you substituted into it the macros, copied and pasted the #include
s (recursively), and removed the comments.
In other words, I was thinking of it as "take a C++ file and process all the #
s and delete all the comments in it".
However, I've recently found this very clear answer about what are the step that GCC performs, and I experimented with those info, finding out that the typical output of g++ -E someSource.cpp
looks like this
# 0 "main.cpp"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "main.cpp"
# 1 "Foo.hpp" 1
struct Foo {
};
# 2 "main.cpp" 2
int main() {
}
which I can farily easly understand what it is, but…
- is it valid C++ code? Clearly I can feed it to
g++
, but that's, I believe, just because it can recognize it and process is accordingly, e.g. skipping the preprocessing step. - Is it the thing known as translation unit? As in, with all those
#
-lines?