473,605 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why isn't there a logical XOR operator?

Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
80 35073
Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the following:
Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?


You mean an operator that returns 1 if exactly one of its operands is
nonzero, and 0 otherwise? Yes, that would be useful. But forget about
the short-circuit semantics. Think about it and you'll see why.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 14 '05 #2
Joona I Palaste <pa*****@cc.hel sinki.fi> scribbled the following:
Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the following:
Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?
You mean an operator that returns 1 if exactly one of its operands is
nonzero, and 0 otherwise? Yes, that would be useful. But forget about
the short-circuit semantics. Think about it and you'll see why.


Also if there were an unary ^ operator, we could write Japanese smileys
into our code. For example:
sashimi ^=^ kawaii;

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"War! Huh! Good God, y'all! What is it good for? We asked Mayor Quimby."
- Kent Brockman
Nov 14 '05 #3
nrk
Christopher Benson-Manica wrote:
Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?

If you write your conditions to be all logical (that is avoid the if ( x )
style idioms), then using the existing xor operator would achieve exactly
the same thing as your proposed ^^, wouldn't it? I mean, there can be no
short-circuit evaluation of an xor operator.

-nrk.
--
Remove devnull for email
Nov 14 '05 #4
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus:
You mean an operator that returns 1 if exactly one of its operands is
nonzero, and 0 otherwise? Yes, that would be useful. But forget about
the short-circuit semantics. Think about it and you'll see why.


Hm, that's true. A ^^ B would have to evaluate A and B... I hadn't
thought of that, and I suppose that was a greater good than &/&&
and |/|| symmetry. Interesting.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #5
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus:
Also if there were an unary ^ operator, we could write Japanese smileys
into our code. For example:
sashimi ^=^ kawaii;


This assumes, of course, that C authors are familiar with the Japanese
emoticon paradigm ^_~

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #6
"nrk" <ra*********@de vnull.verizon.n et> wrote in message
news:ma******** *****@nwrddc01. gnilink.net...
Christopher Benson-Manica wrote:
Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?

If you write your conditions to be all logical (that is avoid the if ( x )
style idioms), then using the existing xor operator would achieve exactly
the same thing as your proposed ^^, wouldn't it? I mean, there can be no
short-circuit evaluation of an xor operator.


(a ^^ b) would be something like ((!!a) != (!!b)). Could
be macrotized rather easily? Could the double bang be
reduced to a single bang on each side?

Nov 14 '05 #7
xarax <xa***@email.co m> scribbled the following:
"nrk" <ra*********@de vnull.verizon.n et> wrote in message
news:ma******** *****@nwrddc01. gnilink.net...
Christopher Benson-Manica wrote:
> Of course one can get the effect with appropriate use of existing
> operators, but a ^^ operator would make for nice symmetry (as well as
> useful to me in something I'm working on). Am I the only one who
> would find it useful?
> If you write your conditions to be all logical (that is avoid the if ( x )
style idioms), then using the existing xor operator would achieve exactly
the same thing as your proposed ^^, wouldn't it? I mean, there can be no
short-circuit evaluation of an xor operator.

(a ^^ b) would be something like ((!!a) != (!!b)). Could
be macrotized rather easily? Could the double bang be
reduced to a single bang on each side?


Yes, ((!!a) != (!!b)) is equivalent to ((!a) != (!b)).

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It was, er, quite bookish."
- Horace Boothroyd
Nov 14 '05 #8
Christopher Benson-Manica wrote:

Of course one can get the effect with appropriate use of existing
operators, but a ^^ operator would make for nice symmetry (as well as
useful to me in something I'm working on). Am I the only one who
would find it useful?


if (!!a ^ !!b) ....

c = !!a ^ !!b;

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #9
nrk
xarax wrote:
"nrk" <ra*********@de vnull.verizon.n et> wrote in message
news:ma******** *****@nwrddc01. gnilink.net...
Christopher Benson-Manica wrote:
> Of course one can get the effect with appropriate use of existing
> operators, but a ^^ operator would make for nice symmetry (as well as
> useful to me in something I'm working on). Am I the only one who
> would find it useful?
>

If you write your conditions to be all logical (that is avoid the if ( x
) style idioms), then using the existing xor operator would achieve
exactly
the same thing as your proposed ^^, wouldn't it? I mean, there can be no
short-circuit evaluation of an xor operator.


(a ^^ b) would be something like ((!!a) != (!!b)). Could
be macrotized rather easily? Could the double bang be
reduced to a single bang on each side?


Yes, as x xor y is the same as x' xor y'. However, while this is pretty
neat, I think it makes the code harder to comprehend than using a straight
xor operation on the logical conditions (maybe its me that gets confused
when seeing negation all over the place).

And for those who believe that the xor shouldn't be used in combining
logical conditions, there is one situation where I have found this to be
eminently useful: when processing command line arguments where two
different options are mutually incompatible, but atleast one of them must
have been specified.

-nrk.

--
Remove devnull for email
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14368
by: user | last post by:
Hi, Is it possible to override assignment, the way that '+' can be overridden for example? Thanks, Toby
14
2321
by: lutorm | last post by:
Hi everyone, I'm trying to use istream_iterators to read a file consisting of pairs of numbers. To do this, I wrote the following: #include <fstream> #include <vector> #include <iterator> using namespace std;
5
1368
by: kenny Nguyen | last post by:
Hi, Does anyone know the operator "=+"? If you do, what special method is related to this operator? Is it the __iadd__ method, but I think this is related to "+=" operator. Thanks, Kenny
67
8614
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used in low-level numerical computations, replacing Fortran in newer projects. Check, for example, sourceforge.net or freshmeat.net But neither language offers a primitive exp operator.
12
2195
by: cody | last post by:
Why can I overload operator== and operator!= separately having different implementations and additionally I can override equals() also having a different implementation. Why not forbid overloading of == and != but instead translate each call of objA==objB automatically in System.Object.Equals(objA, objB). This would remove inconsistencies like myString1==myString2
33
1500
by: SpreadTooThin | last post by:
Can these operators be overloaded? If so. How?
18
3214
by: Ranganath | last post by:
Why is throw keyword considered as an operator?
6
11853
by: Rudi | last post by:
Hello! I'm searching like a similar syntax for if(): int i=5; if (i in ) doSomething; e.g. enum TaskStates {Idle,Proc1,Proc2, ... ProcN}
19
3510
by: C++Liliput | last post by:
I have a custom String class that contains an embedded char* member. The copy constructor, assignment operator etc. are all correctly defined. I need to create a map of my string (say a class called MyString) and an integer i.e. std::map<MyString, int>. Whenever I insert the elements in the map using the subscript operator, I noticed that the copy constructor for MyString is invoked more number of times than if I do it using the insert()...
0
8424
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8415
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.