Mind your language

Discussion of chess software programming and technical issues.

Moderator: Ras

OliverBr
Posts: 865
Joined: Tue Dec 18, 2007 9:38 pm
Location: Munich, Germany
Full name: Dr. Oliver Brausch

Re: Mind your language

Post by OliverBr »

petero2 wrote: Wed Jul 23, 2025 1:16 pm What about viewtopic.php?p=973106#p973106
Yes. That was a bug (albeit without consequences). So there is undefined behavior... from the programmer :roll:
But also from the compiler, because I never got a warning (or used the wrong options).
I guess there are more bugs in the code. 8-)
There is a nasty a with TT-hashtables and repetition. But this has little to do with the programming language, because it also happens in the Java version of a OliThink.

Of course, Java is quite strict on those undefined behaviors. Uninitialized variables are not allowed, you don't have access to free pointers and access to arrays is being checked with IndexOutOfBoundExcpetions thrown.
OliThink GitHub: https://github.com/olithink
Nice arcticle about OlIThink: https://www.chessengeria.eu/post/olithink-oldie-goldie
Chess Engine OliThink Homepage: http://brausch.org/home/chess
jdart
Posts: 4408
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Mind your language

Post by jdart »

I don't find C++'s not being memory-safe to be a problem. The last time I had any memory-related issue like a buffer overrun was quite a while ago. If you use std::array, you get built-in bounds checking. And if you use scoped objects to contain allocated memory, then the memory can be freed automatically when you exit the scope. C++ doesn't enforce these patterns, but it supports them. Still, there are applications for which greater safety is important. This is one reason Java is popular for enterprise applications, and is also the reason Microsoft went to C# for much of its code.

I personally find Rust annoying for several reasons, one of them being that the memory ownership features add additional safety, but at the price of complexity for the programmer.