A Not So Stupid C Mistake
I was reading through a website of "computer stupidities" today when I came across this,
This was quickly dismissed as being an obvious beginner mistake. I
don't think this can be dismissed so quickly without thinking it
through for a moment. Yes, in the example above we will never reach
the last condition where we
return z, but consider the
The same quick dismissal might drop the last "faz" print statement as being an impossible condition. Can you think of a situation where the program would print "faz"?
Our final condition will be reached if
b is equal to
NAN, which is defined by the
IEEE floating-point standard. It is available in C99 from
NAN in any of the comparisons
above will evaluate to false.
So don't be so quick to dismiss code like this.