My impression is that it was an '70's problem with the price of memory affecting hardware manufacturer's choices: namely, have less memory. So due to the lack of available registers in hardware, the XOR swap was developed by clever programmers. As soon as the unavailability of hardware registers disappeared, so did the problem that this addressed. So computer hardware developed since at least the early '80's already solves the problem this solution seeks to solve. Thus making it a non-issue.
Unless programmers are still taught that we live in the 1970's. Then this can screw up some compilers that were raised to understand that the programmers writing the code already knew that.
So apparently now compilers are supposed to solve problems that programmers are putting in practice that solve problems that have already been solved elsewise, but the programmer has yet to understand this.
Why shouldn't programming be a little simpler?
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Okay okay, I give up... In the future, I'll keep stuff like this a secret. When newbie folks see it in code they'll just be stuck wondering "What the hell is THAT?"
EDIT: Also, if I really used this stuff in my own code, don't you think I would have known about the swap-with-self problem off the top of my head? So obviously I don't do this.
Again, you seem to misunderstand the thwarting I've undergone.
Sure it helps to know things about the underlying implementation, but that is not completely or entirely relevant.
Times change.
Just as sure as I can say, "Integer math is faster than floating point math," such things are subject to the times. Surely someone will discover this thread in a decade and try to ask me what I was smoking.
[My answer: a legal tobacco cigarette in the United States in my own garage. This itself may have changed in a decade.]
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Funny you choose that example. I think that ceased to be true a few years ago, at least on the systems I was testing on. It seems like casting between the two is the source of slowness these days. Get your data into doubles and keep it there!
I make assumptions based on obsolete experience, too. I try to challenge my own assumptions as often as possible, but sometimes there just aren't enough useful hours in the day...
> The XOR swap thing merely happens to be among them, but not (yet) in the FAQ.
Are we inany hurry at all to change this? Just curious.
for simple stuff, try to use refs more, they provide cleaner syntax than pointers
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<
>The XOR swap thing merely happens to be among them, but not (yet) in the FAQ.
I believe it's in the C faq.
But I agree with brewbuck, it's a good trick to know, the reason being some expert will come along and ridicule you for not knowing it. Just like if you don't know a certain acronym, you will get the same reaction.
Ridicule the "expert" in return for holding on to archaic, useless trivia.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Some of us can't help but hold on to pretty much everything interesting we ever saw. At times this is a real curse, because it makes me look like a loser who wasted his time memorizing useless facts. Hey, they just go in there and stay there, there's nothing conscious about it
Oh, I know that. It's very much imprinted in my brain, too. But I try to avoid spreading the knowledge about these things.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I suppose the ratio of useful / useless knowledge I have is 0 - at least in integer math.