🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Why no logical XOR operator

#1822
From: Jesper Larsson
Date: Wed, 23 Aug 1995 06:41
35 lines
2101 bytes
In article <MATT.95Aug21165410@physics2.Berkeley.EDU>, Warner Losh <imp@village.org> writes:
>: 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:

[deletia]

>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.

The optimization stuff is nonsense. The difference is that | is bit-
wise, and || is a logical operator that knows only two values: zero
and non-zero. Hence,
   (1 | 2) == 0, i.e. false if interpreted as boolean, but
   (1 || 2) == 1, i.e. true.

The != operator can only be used as xor if you are certain that
logical values are never represented by any other integers than
0 and 1.


Jesper Larsson                                 ,,,    jesper@dna.lu.se
Dept. of Computer Science, Lund University    (o o)    +46 46 22 24908
-------------------------------------------oOO-(_)-OOo----------------
``Bad programming practice can lead to death.''         (P.J. Plauger)
---
[ 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: <41dbtm$ln@nic.lth.se>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <MATT.95Aug21165410@physics2.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 23 Aug 95 06:41:46 GMT
Approved: fjh@cs.mu.oz.au
Return-Path: <daemon@ncar.UCAR.EDU>
From: jesper@dna.lth.se (Jesper Larsson)
Newsgroups: comp.std.c++
Subject: Re: Why no logical XOR operator
X-Original-Date: 22 Aug 1995 19:41:42 GMT
Organization: Dept. of Computer Science
Message-ID: <41dbtm$ln@nic.lth.se>
References: <MATT.95Aug21165410@physics2.Berkeley.EDU>
Reply-To: jesper@dna.lth.se