🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1719

Re^2: Why no logical XOR operator

#1719
From: John Lacey
Date: Fri, 14 Sep 1990 18:59
36 lines
1857 bytes
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
Technical Details
Message-ID: <1990Sep14.185916.2247@basho.uucp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!n8emr!uncle!basho!john
References: <1990Sep12.154515.18460@druid.uucp> <849@usage.csd.unsw.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!n8emr!uncle!basho!john
From: john@basho.uucp (John Lacey)
Newsgroups: comp.std.c
Subject: Re^2: Why no logical XOR operator
Message-ID: <1990Sep14.185916.2247@basho.uucp>
Date: 14 Sep 90 18:59:16 GMT
References: <1990Sep12.154515.18460@druid.uucp> <849@usage.csd.unsw.oz.au>
Organization: Sportsware
Lines: 36