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?
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.
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.]
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
>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. :)
Oh, I know that. It's very much imprinted in my brain, too. But I try to avoid spreading the knowledge about these things.
I suppose the ratio of useful / useless knowledge I have is 0 - at least in integer math. :)