Re: is C necessarily faster than C++

itcp@praxis.co.uk (Tom Parke)
Fri, 23 Jun 1995 04:07:15 GMT

          From comp.compilers

Related articles
[18 earlier articles]
Re: is C necessarily faster than C++ tmb@netcom.com (1995-04-29)
Re: is C necessarily faster than C++ jdean@pysht.cs.washington.edu (1995-05-09)
Re: is C necessarily faster than C++ calder@mumble.cs.Colorado.EDU (1995-05-09)
Re: is C necessarily faster than C++ schow@bnr.ca (stanley (s.t.h.) chow) (1995-05-09)
Re: is C necessarily faster than C++ mike@vlsivie.tuwien.ac.at (1995-05-04)
Re: is C necessarily faster than C++ bill@amber.ssd.hcsc.com (1995-05-16)
Re: is C necessarily faster than C++ itcp@praxis.co.uk (1995-06-23)
Re: is C necessarily faster than C++ jplevyak@violet-femmes.cs.uiuc.edu (1995-06-23)
Re: is C necessarily faster than C++ bill@amber.ssd.hcsc.com (1995-06-30)
Re: is C necessarily faster than C++ bill@amber.ssd.hcsc.com (1995-06-30)
| List of all articles for this month |

Newsgroups: comp.compilers
From: itcp@praxis.co.uk (Tom Parke)
Keywords: C, C++, performance
Organization: Praxis, Bath, U.K.
References: 95-04-202 95-05-109
Date: Fri, 23 Jun 1995 04:07:15 GMT
Status: RO

bill@amber.ssd.hcsc.com (Bill Leonard) writes:


>> Object-oriented programs tend to have very small functions and to make
>> lots of function calls. Virtual functions are both more expensive
>> than regular function and *more importantly* prevent inlining


>This point seems to get raised a lot, but very seldom does anyone tell the
>*whole* story. First of all, one should not make a function virtual in C++
>unless you really need different implementations for different classes.
>But in that case, you would have needed some sort of decision structure if
>you were writing the code in C -- probably a switch statement. So one
>should NEVER compare virtual functions in C++ to ordinary functions in C;
>they can only be properly compared to code selected by a switch statement.


I haven't seen the rest of this thread so forgive me if I mistake the
context here.


In general when comparing programming languages it is important to
focus on how they are actually used, not how they could be used or to
compare features at too low a level.


In this instance I would claim that in practice the C equivalent of
a class with a virtual function and a number of different classes
derived from it is actually a number of different modules with
possibly some common code factored out. The programmer avoids the need
for a switch statement by explicitly calling the version of the
function he requires.


Now a C++ advocate could argue that its no longer a fair comparison,
but if the C++ advocate is also going to argue that C++ code makes
re-use possible and is easier to maintain and extend then he/she has
to accept that these claims assume that the C code isn't written in a
pseudo C++ style which is what I think Bill Leonard is assuming in his
comparison.




--
Tom Parke : itcp@praxis.co.uk : Praxis, 20 Manvers St., Bath BA1 1PX, UK
--


Post a followup to this message

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