C history question

Henry Spencer henry at utzoo.uucp
Tue Sep 12 01:43:51 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?
>What happened to the boolean XOR operator ?  ...

Groan.  This comes up regularly.  The ^^ operator would in fact be of
very limited use.  The big point of && and || is their sequencing
properties, e.g. the second operand of && is evaluated only if the first
is true.  This cannot be done with ^^, which would inherently need to
evaluate both operands.

>(a || b) && (!(a && b)) when a ^^ b is so much "cleaner".

Try "!a != !b", which has the same effect with not many more symbols.
Or if your operands are boolean (0 or 1) to begin with, "a ^ b" or "a != b".

>Can anyone tell me why this was left out of the language ?  

Because nobody considered it useful enough to put it in.

>Is there any chance that some future version of ANSI-C will have it ?

It's very unlikely.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list