Comparative performance of C(gcc) and C++(g++)

John Love-Jensen
Thu Jan 30 15:50:00 GMT 2003

Hi Ivan,

>The dereference between classes in C++ is slower than the function calling but
the reference of class member inside the class is faster than a function call.

Assuming that I understand what you are saying, I disagree on both counts.
But I'm making an assumption as to the equivalent code that you'd write in

>I conclude that if your program is small in a certain number of lines and
files, the using C is better than the use C++, however if your program increases
in lines and files and you can create a group of intensive called in a space of
time functions, a C++ program (with the cares written in this list) could faster
than a C program.

I disagree with both points -- but that depends on what you mean by
"better".  You had mentioned in your previous email that "better" what a
matter of speed and size, which is the "better" that I'm going by here.

Presuming that both C and C++ are well written / written with care, both
languages are good languages in terms of space and speed.

Both languages have a long list of pitfalls, traps, and gotchyas.  One of
the things I like about C and C++ is that most developers are up-front and
forthright about the shortcomings of C or C++.  I don't see a lot of C or
C++ jingoism in the industry.

Both languages are good choices for a broad spectrum of problem domains.

And both languages are inadequate for a broad spectrum of other problem
domains, where Lisp/Scheme/CLOS or Prolog or Smalltalk/Squeak or Java or Ada
or Perl or lovingly handcrafted assembly (for instance) may be better

The problem domain needs to drive the decision as to which programming
language is appropriate.

In most everything that C can do, C++ can be used as a "better C compiler"
without using the object oriented programming, functional programming, or
generative programming features of C++.  That C heritage is one of the
strengths of C++, and at the same time one of the weaknesses of C++.


More information about the Gcc-help mailing list