Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is (in C++ terms) a translation unit?

Status
Not open for further replies.

maluk

Programmer
Oct 12, 2002
79
SG

I have been reading Conversations: Access Restrictions by Jim Hyslop and Herb Sutter in C/C++ Users Journal.

I came across this sentence:

"Please write a test harness that will time the cost of direct access, against inline accessors and non-inline accessors. Be sure that the non-inline accessors are in a separate translation unit."

What is a translation unit? In my understanding. A translation unit is like you should separate your code with other code.

Can anyone give me a clearer meaning of a translation unit?
Thanks in advance!

Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.

- janvier -
 
A translation unit is a section of code that can be compiled on its own. As an example, if you define a class called Widget in widget.h, and provide implementation in widget.cpp, then write a program to use Widgets in main.cpp, you have two translation units. One is widget.cpp along with widget.h and any other headers it includes. The other is main.cpp along with widget.h and any headers it includes.

Put another way, a translation unit is any section of code that can be made into a .o file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top