C history question
Chris Torek
chris at mimsy.UUCP
Tue Sep 12 03:37:04 AEST 1989
In article <575 at calmasd.Prime.COM> wlp at calmasd.Prime.COM (Walter Peterson)
writes:
>C has bitwise operators for AND (&), OR (|) and XOR (^) and boolean
>operator for AND (&&) and OR (||), but not for XOR (^^). Why?
The best explanation I have ever heard is that the important property
of && and || is not their `booleanness', but rather that they are
short-circuit operators (they avoid evaluating the right hand side
whenever the left hand side gives the answer by itself). By definition,
exclusive or cannot short circuit, so the `^^' operator would be
misleading.
>... why make people go to the trouble of writing something like
>(a || b) && (!(a && b)) when a ^^ b is so much "cleaner".
The simplest expression for `boolean xor' is
!a != !b
since `!' is a boolean-normalising `not' operator and inverted
inputs to xor still yeild xor.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list