&
has &&
. |
has ||
. Why doesn't ^
have ^^
?
I understand that it wouldn't be short-circuiting, but it would have different semantics. In C, true
is really any non-zero value. Bitwise XOR is not always the same thing as logical XOR:
int a=strcmp(str1,str2);// evaluates to 1, which is "true"
int b=strcmp(str1,str3);// evaluates to 2, which is also "true"
int c=a ^^ b; // this would be false, since true ^ true = false
int d=a ^ b; //oops, this is true again, it is 3 (^ is bitwise)
Since you can't always rely on a true value being 1
or -1
, wouldn't a ^^
operator be very helpful? I often have to do strange things like this:
if(!!a ^ !!b) // looks strange