Hacker News new | ask | show | jobs
by lfowles 3679 days ago
It's an artifact of implementation. In some zany world, strcmp could return EQUAL_ENUM. What you are ideally expressing is that you want to know that both strings are equal as determined by strcmp, not that the strcmp return value is nonzero. Now it just so happens that EQUAL_ENUM=0 in this world, so a side effect is that !strcmp(...) will still work. And we also have plenty of examples using this shorthand that it doesn't seem unnatural to a lot of devs. (Doesn't make it any less boots-on-head strange... when in Rome, do as the Romans do...)
1 comments

I'm not saying its not screwed up, and I'm sure some enums would be interesting, but they are using it in a logical context so I feel like the ! makes a fair amount of sense.

I do wonder what would have happened if truth had been defined like it is in Forth[1]? That would make me go with the enums.

1) False is 0 (all bits set to 0), and True is -1 (all bits set to 1 giving a twos-complement -1).