logoalt Hacker News

lowbloodsugaryesterday at 8:09 PM3 repliesview on HN

That is a fucking travesty. If there’s one thing we should be able to rely on C for it’s that it works with assembly, and it’s always been the case that 0 is false and any other value is true. That’s a compiler bug as far as I’m concerned. I don’t use C++ because it’s gone in a ludicrous unhelpful direction since 2000 or so, but it’s sad to learn that C of all languages decided to favor pedantry over working code.


Replies

munchleryesterday at 8:17 PM

The code in question is:

    if (sprtemp[frame].rotate == false)
Note that this is explicitly comparing two values, which is very different from checking whether a single value is true. Surely you wouldn't expect -1 == 0 to evaluate to true.
show 1 reply
direwolf20yesterday at 9:00 PM

You're not wrong. The processor has a perfectly good zero/notzero check. There was absolutely no reason for the compiler to check if x^1==0.

show 1 reply
inglor_czyesterday at 9:03 PM

I still remember one of my first teachers of programming softly shaming me for writing a condition like

if (something == true)

I haven't done so ever since (1997), and thus I avoid the contrary (with == false) as well, using ! instead. But I would be a lot less ashamed if I knew that there are such conditions in production software.

I would also never guess that the problem described in the article may occur...