fen
fen

Reputation: 10115

does external linkage increases link/build time?

I've read that it is better to have internal linkage (for variables, free functions, etc) because this will reduce number of symbols being "exported" from particular compilation unit. That way build times could be better.

Is this true?

Another advantage of using internal linkage is that there will not be any problems with names collision.

reference: Large-Scale C++ Software Design

Upvotes: 1

Views: 307

Answers (1)

Emilio Garavaglia
Emilio Garavaglia

Reputation: 20730

In theory yes, but ... C++ evolved towards generic programming. And the introduction of namespaces limits the name collision problems.

It is always more frequent to write programs in form of "headr only libraries" included hierarchically from a single cpp file containing just a main whose purpose is instantiate a "manager object" that takes care of all the orchestration, and supply a last resort "catch" for eventually escaped-out exceptions. Long symbol table can make faster by means of "precompiled headers".

In this sense, all linkage is "internal", since there is nothing to "export".

More in general, little external linkage result in faster linking time, little internal linkage result in faster compile time. The best minimum is most likely when the internal and external tables balance each other. But there are many other important factor to take care of.

I wonder if a book like that can still be considered "good" for today standard: did you note that what it suggest -for example- about iterators is all but what the standard library today do?

Upvotes: 1

Related Questions