A note for C programmers

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: A note for C programmers

Post by syzygy »

bob wrote:
syzygy wrote:Certainly the Linux kernel will NOT properly run when compiled with just any C99 compliant compiler.
Which one doesn't it compile with? It runs on every platform I have seen. Or are you now saying C is not C, that each compiler can implement a "unique C"? :)
It's pretty well known that Linux does not compile with any compiler, and this is not due to other compilers violating the standard. The Linux kernel source relies on much more than the C standard specifies. This is fine, Linux was never meant to be portable across compilers.
Fortunately I do not see this on any machine I happen to run on, which just about includes ALL machines, BTW..
The reason this thread got started is that you saw your compiler suddenly implement a "different C". In reality, crafty relied on more than the C standard specifies and your compiler did not guarantee this kind of "extended C" that you were using.
syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: A note for C programmers

Post by syzygy »

bob wrote:What I SHOULD be able to assume is that the compiler will do its best to implement exactly what I specify in my code.
What you specify in your code is defined by the standard. In case of overflow, the standard says "undefined". Your intention with the code is irrelevant. How can a compiler know your intention if it goes against the standard.
If it produces int overflow, let it produce it. That's the purpose of a compiler, to turn a source into its machine-language equivalent.
You are hopelessly out of date.

The purpose of a C compiler is to implement the standard. It may do a bit more, but you should not rely on it if you don't like surprises.