the logical xor operator!

Bob Alexander alex at dbase.UUCP
Sat Jul 2 04:00:30 AEST 1988


In article <833 at garth.UUCP> smryan at garth.UUCP (Steven Ryan) writes:
>The lack of a boolean exclusive-or is probably cultural. Xor is important
>for bit fiddling, but few predicates use it. An equivalence operator (even
>if it is just a negated xor), on the other hand is useful for boolean but
>not bits.
>

I would guess that much of the reason for including || and && in C was
to provide the advantage of their short-circuiting properties.
Short-circuiting could not be done with ^^.  I wouldn't mind having it
around, for completeness, but I would probably rarely use it.  Just for
kicks, how about:

#define logical(x) ((x) != 0)	/* logical affirmation */
#define logicalxor(x,y) (logical(x) != logical(y)) /* logical xor */
#define logicaleq(x,y) (logical(x) == logical(y)) /* logical equivalence */

For as often as I would use them, this would suffice.  I would probably
use the first one the most.

Disclaimer: I accept no liability for possible misuse of the word
"affirmation".  Furthermore, the above definitions might not work at
all -- haven't tried 'em.



More information about the Comp.std.c mailing list