Why no logical XOR operator

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Sep 14 04:07:41 AEST 1990


In article <1990Sep12.154515.18460 at druid.uucp> darcy at druid.uucp (D'Arcy J.M. Cain) writes:
>Does anyone know why C left out the logical XOR operator?

The C standard left it out because it hasn't been part of C,
and it wouldn't address a severe deficiency, which was the only
valid reason for adding functionality during standardization.

The reason that C hasn't had a "logical exclusive-or operator"
is that it would serve no real purpose.  The reason for specific
"logical and" and "logical or" operators is to obtain the short-
circuit effect; obviously a "logical exclusive-or" would not be
able to short-circuit.

If you really feel like you need one, you can define your own:

	#define XOR(a,b) (((a)!=0 ^ (b)!=0) & 1) /* for example */



More information about the Comp.std.c mailing list