[comp.std.c] Re^2: Why no logical XOR operator

john@basho.uucp (John Lacey) (09/15/90)

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

>From article <1990Sep12.154515.18460@druid.uucp>, by darcy@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@basho.uucp,  or basho!john@cis.ohio-state.edu