Computer Chess Club Archives


Search

Terms

Messages

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

Author: David Rasmussen

Date: 05:50:27 12/26/02

Go up one level in this thread


On December 25, 2002 at 15:38:19, Matt Taylor wrote:

>>Overloading costs nothing, it's a compile time construct and is resolved at
>>compile/link time.
>>Inheritance costs nothing, it too is a compile/link time issue.
>>You know nothing about C++, do you? I didn't think so.
>
>Overloading costs an indirect function call.

What? No it doesn't. Overloading is resolved at compile time by a well defined
set of rules. See The C++ Programming Language 3rd ed. p. 149.

I recommend both of you to read that book and also The Design And Evolution of
C++, to get an understanding of how much care has been taken to not impose
runtime overhead on features that doesn't need it.

> I'm not sure if you can apply const
>to a class like you can apply final to one in Java, but unless the compiler
>knows the class can't be inherited from, it has to make the operator an indirect
>function call.
>

What has this to do with overloading? Overloading means using the same name for
different things. Overriding and virtual functions are something different. I am
responding to "overloading" because that was the word Vincent used.

>>>I had to chose between writing my GUI functionality (database and such)
>>>in C or C++ before i started. Initially i wanted to start it in C++
>>>but in the end i figured out that speed for a chess database is not
>>>unimportant so i wrote it in C.
>>
>>If there was a speed difference for that kind of application, it just goes to
>>show how bad you are at C++ programming, or at programming in general.
>
>C code in C++ is the same speed, but using C++ constructs can be slower.

Or faster. There will not be a speed difference for this kind of application if
done right, even if you have a nice design with abstraction benefits etc.

>Multiple inheritance, polymorphism, etc.
>

You don't have to use those features. And when you do, you would have to do
something similar to obtain the same effect. It's the programmers choice.

>>>But i could of course have done it in C++ as well. In fact if i change
>>>the extension of the code from *.c to *.cpp then it pretty quickly
>>>is c++ code already, the nearly same code being both C and C++. Says
>>>enough to me about speed differences.
>>
>>C++ has nothing to do with extensions, Vincent...
>
>Most compilers I have worked with (Borland, Symantec, Microsoft) decide whether
>to compile C++ or C based on file extension, though you can always pass a flag
>and force C++ rules. I believe GNU C also does this, but I have ignored the
>commandline options except for optimization flags.
>

And this is relevant in what way?

/David



This page took 0.04 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.