On Dec 13, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
James Kanze wrote:
[..]
Most linkers still treat the object file as the unit of
granularity, which means that in a well written general purpose
class, which will be used in a variety of applications, every
non-virtual function will be in a separate source file, so that
the final executable only contains what it needs. (There are
exceptions, of course.)
[..]
I know that some advanced linkers manage to remove unused static
functions from the final program as part of optimizing it. This
is to complement your response, not to contradict it, mind you.
I've heard this as well. The linkers on my principal target
don't, however, and if you're maintaining separate sources for
each function on one platform, it's easier to do it everywhere
than to use two different strategies.
It is more work. For low level classes with lots of more or
less similarly sized functions, it's worth it. But it's not
worth doing everywhere---for example, well over 90% of the code
of my RegularExpression class in the parser, which is invoked by
the constructor. Given that, it's probably not worth breaking
the other functions out into separate files---any user will pick
up 90% of the code anyway. (On the other hand, the parser
itself is complicated enough that it needs to be spread over
several source files. And because I originally developped it on
a 16 bit machine where every byte counted, my current
implementation still does have every function in a separate
file.)
If the class is only going to be used in one application, of
course, there's no point in it. If the function isn't used,
don't even write it, and if it is, it has to be linked in
anyway, so you might as well put it in the same file as the
other functions.
Also, if virtual functions are involved, the compiler will want
to put their address in the vtbl, whether they're invoked or
not. Which means that they will be linked in, so you might as
well put them all in the same source file.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34