Originally Posted by Flesym
Simply use !=
That works with true boolean values, but what about this?
int A = 1, B = 2;
if (A != B) printf("!=\n"); /* compares numerical values */
if ((bool) A != (bool) B) printf("XOR 1\n"); /* same as below but no shorter */
if ((bool) A ^ (bool) B) printf("XOR 2\n"); /* boolean XOR */
When comparing non-bool values, && and || automatically convert the two to perform a true boolean comparison so (bool)
isn't needed. ^ has nothing comparable in that sense, which is especially a problem in C.