"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:gqb2gt$73r$1@news.datemas.de...
Qu0ll wrote:
I come from a Java world where we have tools like ProGuard which
analyze all the components of an application and strip out classes
and members that are not being used. Is there an equivalent in C++
or does this happen automatically?
C++ has a concept, related mostly to templates, that you don't pay for
what you don't use. Compiler implementors develop their tools with
reduced program size in mind, of course, it's always one of the goals.
For example, linkers (the programs that tie different object modules
together) can perform some reduction by not linking modules from which
no function is used.
For example, if I use one or two classes in the
Boost library, do I get the entire library when I link my program?
Most likely not.
Similarly if I use just part of the STL, do I get the whole thing or
just those parts I use?
Only the parts that you use. That's one of the selling points of C++
templates.
The overall reduction in machine code is not always possible by the
compiler/linker, since the use of functions/modules can be dependent
on the data the program has to process. Theoretically, if you have an
exhaustive set of tests, you can run your program under a *coverage*
tool to collect coverage data and then manually remove the code that
is never executed.
Thanks Victor for the prompt, comprehensive reply. So therefore there
is no need for a tool like ProGuard as the linker and the template
mechanism do this automatically. Does this apply to individual classes
defined in the same physical file? That is, will the linker only link
in those that are actually used even when they are defined in the same
compilation unit as some which are not used? In Java we have each class
in a separate file but this doesn't appear to be the way in C++.
separately from your code. When used in your code, each template is
unifying the code). Templates that aren't instantiated, are only
generated for those.