I just have some kind of fundamental perception problem with strcmp, stricmp, compare, etc. I KNOW what they do and I know WHY they do it, but when I’m checking equality I just naturally write “if ( strcmp() )…” It’s backwards logic to me and it just doesn’t occur to me (until later when my code block doesn’t work) to write “if ( 0==strcmp() )…”. I do this all the time and it slows down my development. Anyone got a tip to reverse my brain on this?
It’s like I needed the function to be named “strdoesntcmp”… (yes I know that it couldn’t be used for less- or greater-than that way…). Sure I could use #define or inline to make such a thing but that’s a hack… I just want to reverse my natural thinking on it if that makes sense…
Just think, that comparison is, in fact, subbtraction (the microprocessor instructions are also working in such way). So
strcmpmight be calledstrsub, and in such way zero means that the strings are equal.Or implement the
strcmpspecification on your own. While you work it out, the return values will glue to your mind like1x1.You can think also, that once you have posted to stackOverflow that you are always forgetting
(0==strcmp)and got a lot of confusing answers to it. Once you have this remembered, your mind could not mistake anymore that thecompareoperator is not theequalityoperator.