Question about the term: "Translation Unit". Help me sound smart!

So this term, Translation Unit, has been coming up in my reading more and more often, either that or I just haven't noticed it before. I understand what it is in concept but I wanted to ask if you guys would consider it to be synonymous with the object file or if it should be used in a more generic sense? For example, would "The linker takes the code from each of your source code files and the included headers, pre-processes it, and then outputs it into each of their own respective translation units." be technically and grammatically correct or is it too awkward?

Bonus Question: This just popped into my head as I was typing this. Would the functions from a statically linked shared object file (an .so or .dll file) be considered part of the resulting translation unit? Would the code from a dynamically linked shared object file be considered separate? Again I mean grammatically in regards to the term, I know that when one of these files is statically linked it's code gets written into the binary where as with a dynamic link it does not.
Last edited on
No it's not the same. A translation unit consists of code (text). An object file is what you get after you have compiled the code.
OK, so the translation unit is created before the object file is linked. I missed that little detail since from my perspective linking is all done in all appears as one step. That's good to note.
Last edited on
I think this link describes the term quite well. http://www.efnetcpp.org/wiki/Translation_unit

And from that link:
It consists of the contents of a single source file, plus the contents of any header files directly or indirectly included by it


A single translation unit can be compiled into an object file, library, or executable program.


Would the functions from a statically linked shared object file (an .so or .dll file) be considered part of the resulting translation unit?

No. A library (.a, .lib, .so, .dll) file is not actually compiled as part of the process. The translation unit is created by the pre-processor for the compile stage.

@ jlb: Yeah, it's that second quote you have that threw me off, along with what I said earlier. I think I misread that as "A single translation unit can be compiled into an shared object file, library, or executable program." which is why I thought it was a generic term for the object file.

The second question was the result of my misunderstanding so discussing it becomes moot.

@ Everyone: Thank you for your help guys. This is the kind of thing that I screw up learning this stuff on my own. I'm, glad you guys caught it early.
Last edited on
Topic archived. No new replies allowed.