LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

View Poll Results: XOR, flaw or streamlined?
Flaw 1 33.33%
Streamlined 2 66.67%
Voters: 3. You may not vote on this poll

Reply
 
Search this Thread
Old 11-04-2007, 08:40 PM   #1
xadrith
Member
 
Registered: Oct 2007
Distribution: Slack 12.1
Posts: 43

Rep: Reputation: 15
Absence of XOR in C++, flaw or streamlined?


Just curious as to others' interpretations on this.

If it were to be considered streamlined that this operator is excluded... is it because the particular operator that would be required would take up just a little bit more resource?

Seems silly that it takes all three logical operators to form an exclusive-OR operation in C++ and then to call it streamlined (by some).

xD
 
Old 11-04-2007, 08:48 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
C++ has XOR. It's '^', just like in C.
 
Old 11-04-2007, 09:30 PM   #3
xadrith
Member
 
Registered: Oct 2007
Distribution: Slack 12.1
Posts: 43

Original Poster
Rep: Reputation: 15
Well, I'll be... thanks.

Ol' Herbert spent a whole page explaining this. And things have changed... things always change.

indeed... thanks,
xD
 
Old 11-08-2007, 11:29 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Keep in mind that ^ is bitwise and values need to be converted to bool in order for it to be a boolean operation. There's no boolean XOR (in the way && corresponds to &) as far as I know.
ta0kira
 
Old 11-09-2007, 07:12 PM   #5
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
Quote:
Originally Posted by ta0kira View Post
...There's no boolean XOR (in the way && corresponds to &) as far as I know.
ta0kira
Simply use !=
 
Old 11-10-2007, 01:24 AM   #6
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
Ol' Herbert !? You're not talking about "mr." Schildt, are you?
 
Old 11-10-2007, 05:56 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by Flesym View Post
Simply use !=
That works with true boolean values, but what about this?
Code:
#include <stdio.h>

int main()
{
	int A = 1, B = 2;
	if (A != B)               printf("!=\n");    /* compares numerical values */
	if ((bool) A != (bool) B) printf("XOR 1\n"); /* same as below but no shorter */
	if ((bool) A ^ (bool) B)  printf("XOR 2\n"); /* boolean XOR */
}
When comparing non-bool values, && and || automatically convert the two to perform a true boolean comparison so (bool) isn't needed. ^ has nothing comparable in that sense, which is especially a problem in C.
ta0kira

Last edited by ta0kira; 11-10-2007 at 05:59 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Absence of PAM kills Slack dunric Slackware 12 08-30-2005 09:07 AM
XOR - sound or mouse in Mandrake 10.1 Official david_j Mandriva 1 02-12-2005 04:43 AM
Would like to give my impressions of linux after an absence of 8 years Xeys_00 Linux - Newbie 7 04-28-2004 12:56 PM
Streamlined Fedora Brother Michael Fedora 3 04-14-2004 06:58 PM
whats the point in Xor encryption ? qwijibow Linux - Security 26 02-08-2004 02:37 PM


All times are GMT -5. The time now is 07:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration