Hi again
I was thinking which language is fastest at chess programming, c or c++ ?
I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
regards
Ethan Ara
c vs c++
Moderators: hgm, Rebel, chrisw
-
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: c vs c++
I'd be surprised if it many any significant difference.ethanara wrote:I was thinking which language is fastest at chess programming, c or c++ ?
A waste of time, I expect.I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
To get a C++ version of micromax, simply compile it using a C++ (rather than a C) compiler. A C version of of Stockfish will be a LOT of work, since it makes fairly intensive use of templates. And again, I suspect it's a waste of time.
-
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: c vs c++
They both allow inline assembly so they're equally fast
More seriously, since C++ is for all practical purposes a superset of C, it cannot possibly be slower than C assuming equally good compilers.
This of course doesn't mean it's worth it to use the extra features C++ has in order to get better performance, in fact some of them can be counter productive for performance. On the other hand some people have success using things like templates to automatically generate efficient code tailored for very specific situations. This is also possible in C but not as easy. So C++ may have a performance advantage for the same effort in some situations (but I doubt it's a big advantage or even close to it...).
More seriously, since C++ is for all practical purposes a superset of C, it cannot possibly be slower than C assuming equally good compilers.
This of course doesn't mean it's worth it to use the extra features C++ has in order to get better performance, in fact some of them can be counter productive for performance. On the other hand some people have success using things like templates to automatically generate efficient code tailored for very specific situations. This is also possible in C but not as easy. So C++ may have a performance advantage for the same effort in some situations (but I doubt it's a big advantage or even close to it...).
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: c vs c++
If you know what you are doing, there is absolutely no difference. If you get hung up on creating and destroying objects willy-nilly in the search or evaluation, C will win by a wide margin.ethanara wrote:Hi again
I was thinking which language is fastest at chess programming, c or c++ ?
I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
regards
Ethan Ara
-
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: c vs c++
exactly!bob wrote:If you know what you are doing, there is absolutely no difference. If you get hung up on creating and destroying objects willy-nilly in the search or evaluation, C will win by a wide margin.ethanara wrote:Hi again
I was thinking which language is fastest at chess programming, c or c++ ?
I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
regards
Ethan Ara
the only problem is that the intricacies of C++ have now become so complex that, in fact, very few C++ programmers know what they are doing...
-
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: c vs c++
When the programmer understands all of what a C++ compiler actually does, then C++ code is almost as efficient as C code. StockFish is one of the rare examples of perfect C++ code.my general advice is that so long as you dont understand exactly what the C++ compiler does, ie you could write a C equivalent of it, then you shouldn't be writing in C++. So much bad code is being written in C++ by people who have no understanding of what they're doing...ethanara wrote:Hi again
I was thinking which language is fastest at chess programming, c or c++ ?
I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
regards
Ethan Ara
Also, and contrary to popular belief, there nothing C++ can do that C can't do. The whole GNU/Linux operating system is written in C. even GUI programming (the best example being the GTK API and the GNOME desktop).
Last edited by lucasart on Mon Jul 11, 2011 6:39 pm, edited 1 time in total.
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: c vs c++
Regarding to avoid unwanted hidden copies the rules are very simple and I think any average programmer can avoid the pitfalls if he is aware enough of what he is doing when coding and to be aware is really the key word here when programming and even more when programming a chess engine, otherwise you type on your keyboard monkey style and in this (not so uncommon) case no language can come to rescue.lucasart wrote:exactly!bob wrote:If you know what you are doing, there is absolutely no difference. If you get hung up on creating and destroying objects willy-nilly in the search or evaluation, C will win by a wide margin.ethanara wrote:Hi again
I was thinking which language is fastest at chess programming, c or c++ ?
I think it would be possible to make a c++ version of micromax and test result, or making a c version of stockfish
regards
Ethan Ara
the only problem is that the intricacies of C++ have now become so complex that, in fact, very few C++ programmers know what they are doing...
Regarding the language choice, it is actually the opposite: you know one language then you write your chess engine in that language. Wondering if it is better C or C++ suggests that perhaps the first prerequisite (knowing a language) is missing
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: c vs c++
Also, and contrary to popular belief, there nothing C can do that assembly can't do.lucasart wrote: Also, and contrary to popular belief, there nothing C++ can do that C can't do.
This is just a joke Lucas, thanks for your kind words on SF !
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: c vs c++
BTW, talking about languages, I stumbled across this go language:
http://golang.org/
I have to say that it has some good ideas...it is not bad ! But I have not coded in this language, so my opinion is very very just a guess.
http://golang.org/
I have to say that it has some good ideas...it is not bad ! But I have not coded in this language, so my opinion is very very just a guess.
-
- Posts: 134
- Joined: Mon May 16, 2011 6:58 pm
- Location: Denmark
Re: c vs c++
Interesting. Nearly all things made by google has been succesful, so maybe one will give it a try.mcostalba wrote:BTW, talking about languages, I stumbled across this go language:
http://golang.org/
I have to say that it has some good ideas...it is not bad ! But I have not coded in this language, so my opinion is very very just a guess.
I was thinking if its speed is comparable to c / c++ ?
Also, is there any modern engines made in ASM ?
Regards,
Ethan