Saturday, June 27, 2020

Descartes and C Programming

"Whatever I have up till now accepted as most true and assured I have gotten either from the sense or through the senses. But from time to time I have found that the senses deceive, and it is prudent never to trust completely those who have deceived us even once." - René Descartes


I have always been moved by the nature of thought that produced the ideas of Descartes and the Cartesian coordinate. Also, I am writing C codes for the last thirteen years. I would say that I find it to be the closest of the idea of the Cartesian coordinate.

I have not yet went through one standards of the C language fully. I have found C to be intuitive and I thought know how things can be achieved with it. I have been proven wrong earlier as well. Very recently, I wrote a code similar to this and it crashed with newer GCC.

It turns out, that if I perform pointer arithmetic, I tell the compiler that it is a valid pointer and it is guaranteed to be not equal to NULL and such checks can be optimised out (or "in")!

I tried with GCC-8.3.0 and 9.3.0 with "-O3" option and the latter crashes because the while always evaluates to true.

Please refrain from suggesting "better" ways to do something. This post is contains a snippet and not the whole code and the post is about standard behaviour and not how to write better C code ;)

Just like life, it is wise to be not too trusting with C.