Thomas said:
I question the truth of this statement. Can you provide an example of
a C program that is faster when compiled as a C program than as a C++
program? And if that's not what you meant, then what overhead do you
believe a program using C++ idioms brings that results in it being
slower than an equivalent C program that doesn't use those idioms?
I was thinking of both languages without any compiler optimization
except what is intrinsic to the languages (e.g., #define and inline,
the latter of which is actually only a hint to the compiler and which
may be ignored while the former cannot be). Second, as you note, most
any C program will run under C++, but I was thinking of a "pure" C and
a "pure" C++ program using their respective idioms.
That being said, since any C++ program can be transformed into a "pure"
C program, there's really not that much difference, save that the C++
program (or the same program transformed into C) would have a few more
pointers passed around and a few more dereferences before function
calls. In general, I agree that these are negligible (though non-zero),
so while my statement that C-style programs "can often beat" C++-style
programs may be technically correct, in practice there *usually* isn't
all that much difference.
Cheers! --M