Standard extensions (logical exclusive or)
David Stevens
abv at pucc-h
Fri Nov 9 09:03:40 AEST 1984
<bugs bugs bugs>
Joe Orost says:
>I disagree. The bitwise operators operate on every bit of their arguments,
>whereas the logical operators operate on zero -vs- non-zero. Therefore, i^j
>is not the same as i^^j. i^^j is equivalent to:
> i?(j?0:1):(j?1:0)
>which is only the same as i^j when i and j are 0 or 1.
>
>Therefore, I vote for the ^^ operator.
>
> regards,
> joe
>
I disagree with you. The two important features of && over & are
that 1) it is logical (not bitwise), and 2) it is short-circuit.
Boolean expressions evaluate to 0 or 1, so ^==^^ in this case, and
since both expressions must be evaluated, you gain nothing by adding ^^.
If you are checking for "nonzeroness", then neither "a!=b" (as someone else
suggested) nor "a^b" is equivalent to a^^b, but the question here is whether,
for "nonzeroness", "(a!=0) != (b!=0)", or "(a!=0) ^ (b!=0)" is so ugly that
an extension to include ^^ is reasonable. If a and b are not *really* logical
expressions, then I say that what you want is "!=0", and not some magic to
make them be treated like logcial expressions. I vote no for ^^.
----------
David L Stevens
{decvax|harpo|ihnp4|inuxc|seismo|ucbvax}!pur-ee!pucc-h:abv
DISCLAIMER:
The opinions expressed above are not necessarily my own, or anyone else's.
More information about the Comp.lang.c
mailing list