the logical xor operator!
John F. Haugh II
jfh at rpp386.UUCP
Mon Jun 27 01:29:06 AEST 1988
In article <1310 at ark.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>Of course the way to come around the deficiency is:
>
> if (!(expr1) != !(expr2)) {
> ...
> }
>
>but this only works if !0 always evaluates to the same value (viz. 1), that is,
>the optimizer is not allowed to f*ck around with the comparison.
>!0 is indeed a constant, isn't it?
>--
>I'd rather live in Russia |Maarten Litmaath @ Free U Amsterdam:
> than in South-Africa... |maart at cs.vu.nl, mcvax!botter!ark!maart
[ hey, chris, here is topic #2 for your posting ]
which, as this discussion went a few months ago, is exactly the case. the
code you've writen above, modulo any blindness on my part, should work perfect
as an exclusive-or function. remember, exclusive-or is the not-equivalant
operator, it returns true when the two operands are not boolean equivalant.
the implied comparision against zero is performed automagically in the case
of || and &&.
as far as the optimizer is concerned, it should still be able to perform
any optimizations which would be allowed for any other boolean operators,
except you can't short circuit != or == as you can && and ||. in particular,
i believe (a == 0)^(b == 0) most likely can't be as well optimized as
(a == 0)!=(b == 0). i can't prove this to be true, but i very well suspect
it may be.
- john.
ps - your .signature is thought provoking. i can't decide whether i'd
rather live in a large communist country which oppresses blacks
or a small capitalist country which oppresses blacks. hard choice.
--
John F. Haugh II +--------- Cute Chocolate Quote ---------
HASA, Division "S" | "USENET should not be confused with
UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp | -- with my apologizes
More information about the Comp.std.c
mailing list