C
Charlie Gordon
Keith Thompson said:[...]Ark Khasin said:Sorry. I ought to be more careful. Here is a repaired version:
int cmpneq(int a, int b) {return a^b;}
Bitwise operations on signed types always make me nervous.
In this case, for an implementation that uses ones'-complement or
sign-and-magnitude, a^b will fail if a is +0 and b is -0.
Close, but no cigar ;-)
On those obsolete museum pieces, in the case you describe, a^b would be -0,
a value that compares equal to 0, so the result is correct. But you are
just off by a little: if a=1 and b=-1, a^b yields -0 as well, which of
course is a problem.
The language has a built-in != operator. Just use it. Don't
micro-optimize unless it's absolutely necessary.
Absolutely!