🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1789

Re: Why no logical XOR operator

#1789
From: Warner Losh
Date: Mon, 21 Aug 1995 23:54
39 lines
1723 bytes
Distribution:
: I'm wondering why there isn't a logical XOR operator (eg. ^^)
: though there is a bitwise one (ie. ^).

The '!=' operator is logically the same as XOR.  It produces the same
truth table for bool values as you'd expect an xor operator to:

	a != b

	a/b	true	false
	true	false	true
	false	true	false

However, the precidence of this operator is not what you'd want it to
be to really use XOR.  Eg
	if (a != b || c !=d)
parses "correctly" but
	if (a != b != c != d)
doesn't.  This is easy to fix with parens:
	if ((a != b) != (c != d)).

However, since ^ has a lower precedence than !=, you could write
something like
	if (a != b ^ c != d)
and have no need for parens.

There can be no short circuit done for this operator, since you can't
know the result of the operator until you've evaluated both sides.
Maybe that is why it isn't in the language.  I was once told that C
had both | and || because one was optimized and the other wasn't.
Since it is impossible to optimize xor, there is no ^^ operator.  I'm
not sure how true this actually is.

Warner

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MATT.95Aug21165410@physics2.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <40sp1t$lbc@cd4680fs.rrze.uni-erlangen.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: Warner Losh <imp@village.org>
Newsgroups: comp.std.c++
Subject: Re: Why no logical XOR operator
Date: 21 Aug 1995 23:54:10 GMT
Organization: <none>
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Aug21165410@physics2.Berkeley.EDU>
References: <40sp1t$lbc@cd4680fs.rrze.uni-erlangen.de>
NNTP-Posting-Host: physics2.berkeley.edu