[prog] School problem, C++ and cout.precision(2);

Akkana akkana at shallowsky.com
Sun Nov 24 01:00:45 EST 2002


Ganesh Swami writes:
> How many people use C++ completely ? Actually very few. Is it worth
> learning Templates and other advanced C++ features ?

It's worth learning templates -- they're cool, can be very useful,
and some projects use them heavily.

A few years ago, there were huge differences between various compilers
on how templates worked and how much of the template standard was
implemented, so it was extremely difficult to write template code
which was portable among many platforms.  But most of those compilers
have died out by now, and if you only need to work on two or three
modern compilers, it's no longer a major issue.

> I personally do not like streams. Its more trouble than ease. And, I
> love strongly typed languages (you can call PHP an exception ;-))

I find the same thing, largely because I tend to use a lot of functions
that use stdio and it's not a good idea to mix stdio and streams output
(buffering can cause lines to show up out of order).  But for a
relatively small C++-only project, streams certainly can make it
easy to output complex classes, compared to C I/O.

> The `overhead' of C++ is largely a myth.  There's a hard and fast rule
> in the C++ community: You Don't Pay For What You Don't Use.  If you

Ganesh Swami writes:
> Absolutely. A C program thru a C and a C++ compiler should yield similar
> results.

Not entirely true.  You still get name mangling, which can slow down
shared library loading at runtime (usually only an issue with a big
project); and you pick up a somewhat larger code size (from libstdc++
functions, I guess).  I ported some code to PalmOS a year or so ago
that started out in C++, but then I found that it wouldn't fit in the 
PalmOS page size when built with C++; it wasn't actually using any
C++ functions (the author had built for C++ because his compiler gave
better warnings for C++ than it did for C) and when I switched to
straight C, the executable was significantly smaller and now was
able to fit in the space available.

So, in other words, it might matter for the very large or the very
small.  For most projects in between -- for example, if you're writing
a small gui app to run on desktop machines -- I wouldn't consider C++
overhead to be a major reason for choosing one language or GUI toolkit
over another.

	...Akkana



More information about the Programming mailing list