PJ, please stop putting words in my mouth, get off your high horse about
zealotry, and listen for a change. Instead of that asinine sequence of
arguments that you wrote, what I said was:
- C++ has features "turned on" by default that _do_ add inefficiencies in
the
code. These inefficiencies afford features such as exception handling that
do
not exist in C without manual addition.
- These features can be turned off by conscientiously managing your code
(or
even managing your compiler switches), thus allowing your C++ code to
match
the efficiency of C.
And that's where I part company with your quibble. There's
nothing in the C++ Standard that requires the kind of
efficiencies you claim, and in fact not all compilers
provide them. There's an important missing qualifier here.
Notice that nowhere in my statements have I said that C++ overhead is
"nonexistent".
But that indeed was what was asserted at the beginning of
this thread, and defended in various ways by you and others.
Your first post emphasized the phrase "exactly zero" three
times, while carefully decorating it with qualifiers.
There are important *disguised* qualifiers there.
I said that C++ code is not /necessarily/ less efficient
than
C.
And I've agreed that, if you work at it and if you have a
suitable compiler, you can achieve that goal for some
class of programs.
We are always dependent on compiler implementation for the proper
generation
of our code. Just because _not all_ compilers support a standard construct
doesn't mean that the construct is worthless, or not a good practice.
And I didn't say that. It's not a worthless practice; it can
be "good" if carefully enforced.
As
far
as I can tell, the MSVC and g++ compilers (as well as my embedded
compiler,
Diab) support the suppression of exception handling via the throw()
specification. That seems to be a large enough base of compiler
installations
to me. How large of a base would you like to see before a compiler's
implementation becomes more than a curiosity in your eyes?
My experiments with gcc are not as unequivocally positive as
yours. Nor is it true of all the embedded compilers I've
encountered. And I've never dubbed the "throw()" practice a
mere curiosity. I observed instead that:
a) It violates the principle that those who no nothing about
a feature (exceptions in this case) don't pay for it.
b) It's a fragile programming technique to require widespread
decoration of function declarations.
c) Even then, it's not universally guaranteed to eliminate
*all* space and time overheads with all compilers.
Those are important, practical, qualifiers.
Having said all that, in most applications the overhead caused by leaving
the
C++ features "on" is not significant.
And I pointed that out in my first posting.
Where they do count, such as in the
real-time embedded world that I live in, aggressive management of code is
par
for the course, not just for C++ overhead reasons, but for other
efficiency
reasons such as type conversions, word sizes, and hardware considerations.
Well, there's aggressive and there's aggressive, in my book.
Doing the obvious to save time and space is par for the
course. Doing magic by rote is fragile.
Look: I understand your arguments and agree with most of them--and it
seems
that the converse is true as well. Our differences lie in the extent to
which
we are willing to advocate code management to (re)gain efficiencies in
C++. If
that makes you want to use a dismissive label like "zealot" on me, then I
at
least claim to be a _practical_ zealot, because I practice just that sort
of
"zealotry" in efficiency-sensitive portions of my code every day, with
positive results. Your mileage may vary.
My charge of zealotry is to the OP, who proclaimed that such
overheads are nonexistent. But I have almost as much problem
with apologists who seem to say, "Well, he's not completely
crazy *all* the time." (This brouhaha reminds me of the
elderly lady who calls the cops, complaining that a man
across the street is behaving indecently before his window.
The cop looks and sees nothing. "Stand on the bed!" she
insists.)
The fundamental issue is whether programming in C++ yields
programs that are larger and slower than comparable programs
written in C. In my extensive experience, the simple answer
is yes. The most prudent course for a project manager is to
assume 5 to 15 per cent overheads, and take for granted that
the benefits of C++ will justify the extra costs. I went
through a similar period with C a few decades ago, selling
it against assembly language. I agree the overheads can be
managed, often significantly reduced; and it's worth teaching
people how to do so. But pretending that the problem doesn't
exist at all does not help our credibility with a rightly
critical audience of potential new users.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com