Re^2: Why no logical XOR operator

John Lacey john at basho.uucp
Sat Sep 15 04:59:16 AEST 1990


cameron at usage.csd.oz (Cameron Simpson,Uhmmm..???? Who knows) writes:

>From article <1990Sep12.154515.18460 at druid.uucp>, by darcy at druid.uucp (D'Arcy J.M. Cain):
>| [ essentially, the expression
	(!x && y) || (x && !y)  ]

>| If there was such a thing as a '^^' operator.  Does anyone know why C left
>| out the logical XOR operator?

>I can envisage two reasons:
>	- It looks like && and ||, so it should short-circuit.
>	  This doesn't make sense for XOR.

Sure it does.  Short circuit simply means that as soon as the value of
the expression can be determined, no further expressions should be 
evaluated.  An exclusive or expression can't be determined without 
evaluating both sub-expressions, but that doesn't mean that it isn't 
short circuited.

>	- What's wrong with saying:
>		!!x ^ !!y
>	  which accomplishes exactly what you want.

What?  If x = y = 1, then !!x = !!y = 1, and 1 ^ 1 = 1, but x ^^ y = 0.

>	  I'm tempted to use the phrase "insufficient utility".

I can agree with you here.  Certainly I haven't needed an exclusive or
operator as much as I need && and ||.  Nonetheless, the decision was,
we must admit, more pragmatic than elegant.  The logical operator set
is neither complete nor minimal (nands, anyone? :-).  If you like,
simply use Lisp, or C++, or [ ... ], and create the exclusive or
yourself.  C doesn't have it, probably never will.

-- 
John Lacey,  john at basho.uucp,  or basho!john at cis.ohio-state.edu



More information about the Comp.std.c mailing list