C
Chris Croughton
With this, on the other hand, I agree. Inverted strcmp sense errors
are one of the more common sort I find in others' code.
I've made it a lot in my own. I do usually catch the fault before I've
even finished the statement, but it's one I've had to train myself to
catch.
I don't
remember making one myself since I adopted Peter van der Linden's
macro, which I think does improve readability significantly. For
example:
#define MySTRCMP(s1, op, s2) (strcmp(s1, s2) op 0)
if (MySTRCMP(password, ==, "drowssap"))
Inlining the operator brings string comparisons syntactically closer
to their numeric cousins.
Oh, I like that! Yes, that makes it a lot more obvious. I would
probably call the macro STRCOMPARE, but that's a matter of taste...
Chris C