I think Mr. Kanze and others have talked about giving functions
their own source/implementation files in order to minimize the
size of executables. I sometimes split a function off into a
separate file like that.
The case for fstream is different, because it is a template.
Basically, there are three cases to consider:
-- Non-template non-virtual functions: There is no difference
between C and C++ here. The granularity of the linker (at
least most linkers) is the object file. If you put each of
your functions in a separate source file, then the linker
will pull in exactly what is needed, no more, no less. If
you put all of your functions in one big source file, the
linker will plu in all of your functions. Both in C and in
C+++.
-- Virtual functions: A virtual function is "used" any time the
class is instantiated (since its address will appear in the
vtable). If you instantiate a class of type C, then all of
the virtual functions of class C will be pulled in,
regardless of how you organize your source files.
-- Function templates (and member functions of class
templates): The linker generally has nothing to do with
this. The templates will be instantiated if they are used,
and not otherwise. (And here, again, virtual member
functions are "used" anytime the class itself is
instantiated.)
std::fstream is a class template, so the last point applies. It
does have virtual functions, but one, the destructor, will be
used, forceably, and the only other one, rdbuf, is more or less
trivial.
In fact, in this case, unless the implementation uses fprintf or
sprintf in its implementation, the C++ model should result in
far less code being pulled in. If you use printf, for example,
you will pull in all of the code for floating point formatting,
even if your program doesn't have a single floating point value
in it. (Older readers may remember that early implementations
of C generally had two implementations of the library, one with
floating point support, and one without. Because the floating
point support did take up a lot of space, and without virtual
memory and with only 64KB of memory, that space was important.)