3 ms·
I always go with strcmp(...) == 0 instead of !strcmp(...). This better reinforces my mental model of it (like many comparison functions) having 3 possible retu
by MaulingMonkey 10y ago
I always go with strcmp(...) == 0 instead of !strcmp(...).
This better reinforces my mental model of it (like many comparison functions) having 3 possible return values: <0, =0, or >0. !strcmp(...) may be terser, but it is illogical in that logical not isn't an operator. I dig using it on booleans, or "booleanish" values (null vs non-null pointers), but this conceptual tri-state isn't even "booleanish". But C didn't have a proper bool type for awhile, and C++ inherited it's baggage, so they'll compile it.
Meanwhile C# doesn't even think my "booleanish" tests are logical enough to allow to compile - no null reference tests with "operator!" for me.