Computer Chess Club Archives




Subject: Re: C and C++ --- NPS

Author: David Rasmussen

Date: 02:29:47 12/24/02

Go up one level in this thread

On December 23, 2002 at 21:33:50, Matt Taylor wrote:

>The biggest hit you take in C++ is virtual functions, and inevitably people use
>them. The virtual functions are very damaging due to the fact that they're
>implemented with a function pointer, and at the machine level it translates into
>an indirect call. The indirect calls branch mispredict because the CPU can't
>figure out ahead-of-time where you're calling to, and branch mispredicts are
>Unfortunately, not using virtual functions (mostly) defeats the benefits you
>would get from OO here.

First of all, that is a poor understanding of OO.
Secondly, OO isn't the only virtue of C++. By far.

You would only use virtual functions when you need polymorphism. And if you
wanted to do that without virtual functions, you would need some other form of
dispatch such as a switch statement. Many different tests shows that a function
call and a switch statement isn't faster than a virtual function call. In fact
it is slower.
All of this doesn't matter, as there is no obligation to use virtual functions
in a chess program to use C++ successfully.

>If you convert to C++ without using virtual functions, you probably won't take
>much of a hit at all. Personally, I've never seen a -need- to convert to C++.

I see no need to use an inferior language to express the same thing for no gain
at all. C++ gives my type safety, better I/O and a lot more.

>can implement my OO in C, and it simplifies linking because C doesn't have name

Is that an issue? It hasn't been an issue for me at all.


This page took 0.07 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.