C++ and C

Dave Ciemiewicz ciemo at bananapc.wpd.sgi.com
Mon Feb 26 11:32:57 AEST 1990


After some sanity checking by a fellow engineer, I must clarify a few points.

In article <4534 at odin.SGI.COM>, ciemo at bananapc.wpd.sgi.com (Dave
Ciemiewicz) writes:
> In article <205*doelz at urz.unibas.ch>, doelz at urz.unibas.ch (Reinhard
> Doelz) writes:
> > Hi , 
> > we are about rewriting our graphics application in order to tune code. 
> > We have some own object-oriented modules which would fit 
> > pretty nicely in C++ structures. However, as tuning is the 
> > ultimate target, does anyone know about 
> > 
> > *   C++ performance in comparison to 'plain' C modular structures
> 
> It really does depend on your application and how you implement your C++
> classes and how you previously implemented the same data abstractions in
> 'plain' C.  For instance, the use of C++ derived classes and virtual member
> functions can produce faster code than might be equivalently implemented
> using a data type tag and switch statement in C.  Judicious use of C++ inline
> functions can also speedup some code.
> 
> Unfortunately, no one can give you a pat answer one way or another.  There
> have been some claims made on comp.lang.c++ though I haven't followed those
> discussions in awhile.

Including me.  The sanity check of a test program definitely showed me that
switch statements can produce faster code than using virtual functions and
not as I claimed in the prior message.  However, maintaining the code which
uses the virtual functions is easier.

By-the-by, I just proved this to myself using C++ and pixie.  Sigh.  More
proof you can't rely on hearsay to see that one thing is faster than another.
The proof is in the profile.

> > 
> > *   Optimizer issues: problems with O3?
> 
> The AT&T C++ Translator from SGI just produces C code.  There should not be
> any problems with using -O3 optimization.
> 

There is an issue concerning -O3 optimization.  -O3 and -c are mutually
exclusive with the MIPS cc.  The C++ translator uses the -c flag in the
creation of object code.  Hence, you will need to have C++ generate the
intermediate ..c files and then manually compile them together using
cc -O3.  Ugly, but it will still provides the -O3 optimization.

						--- Ciemo



More information about the Comp.sys.sgi mailing list