Will C++ compilers ever be better than C compilers?

mayan@watson.ibm.com (Mayan Moudgill)
2 Aug 1998 23:59:13 -0400

          From comp.compilers

Related articles
Will C++ compilers ever be better than C compilers? mayan@watson.ibm.com (1998-08-02)
Re: Will C++ compilers ever be better than C compilers? qjackson@wave.home.com (Quinn Tyler Jackson) (1998-08-03)
Re: Will C++ compilers ever be better than C compilers? bill@amber.ssd.csd.harris.com (1998-08-03)
Re: Will C++ compilers ever be better than C compilers? michael.ball@Eng.Sun.COM (Michael Ball) (1998-08-03)
Re: Will C++ compilers ever be better than C compilers? danielv@crt.umontreal.ca (Daniel Villeneuve) (1998-08-03)
Re: Will C++ compilers ever be better than C compilers? jeff@jeff-jackson.com (Jeff Jackson) (1998-08-03)
Re: Will C++ compilers ever be better than C compilers? bob.morgan@digital.com (1998-08-03)
[8 later articles]
| List of all articles for this month |

From: mayan@watson.ibm.com (Mayan Moudgill)
Newsgroups: comp.compilers
Date: 2 Aug 1998 23:59:13 -0400
Organization: IBM_Research
Keywords: C, C++, performance, question, comment

Some of us were having an argument about the performance of C++
vs. C programs, and I made the statement that C programs would
be faster than C++ programs, because of the compilers. The rebuttal
was that
"you can always write C++ programs in the C-like subset
[C + classes + in-lining + const], and the performance
would be the same".


My claim was that one would have to compile such programs with a C++
compiler, and the compiler would not be as "optimizing" as a C compiler.


My reasons were:
1) In practice the ultimate size of a compiler is constrained, either
by the man-power available to code, test and debug the compiler, or
even given unlimited resources, by the fact that one can only
add so much to a program (compiler) before it starts breaking
under the weight of the cumulative changes.


Given that C++ has more features than C, more (most?) of a C++
compiler will be devoted to "getting the features right" than
to optimizations - more work will be needed in the front-end
than in the back-end.


2) The effort of implementing an optimization may be higher in C++, because
it has to work correctly in more contexts (what happens if there
is an exception? what if it is multiply inherited?)
The effort of testing the optimization is definitely higher in C++;
lots more test cases have to be run in C++ to check the correctness
of an optimization than in C.


Consequently, for the same amount of effort, fewer optimizations
will be implemented in C++ than in C.


3) To get "OO"-ish written in C++ programs to work efficiently requires
optimizations that are irrelevant in C (consider inter-procedural
type propagation to convert virtual function calls to function
calls).


Consequently, the optimizations that are written may be irrelevant
to the performance of "C subset" C++ code.


To summarize:
C++ compilers will produce code with lower performance than
C compilers on equivalent code, because of the extra features of
C++. This will occur because:
1) less resources will be available for performance
optimizations
2) more resources are needed to implement and test the
same optimization in C++ compared to C.
3) much of the available optimization resources will be
allocated to optimizations irrelevant to
"C subset" code.


Do you agree?
Can you provide concrete examples?


Thanks


Mayan
--
| Mayan Moudgill
| mayan@watson.ibm.com
[Responses with analysis and examples welcome. Responses with wild
unsupported speculation less welcome unless they're really interesting.
-John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.