Richard Heathfield
Guest
Posts: n/a

 06-07-2007
Keith Thompson said:

> Ben Bacarisse <(E-Mail Removed)> writes:

<snip>

>> a and b have their stored value modified only once (assuming a
>> sequence point just prior to this, of course) and to me reading of
>> the prior value of both a and b are used only to determine the value
>> stored. What have I missed?

>
> I *think* you're right. Perhaps Richard was thinking of the "correct"
> form of the xor swap kludge:
>
> a^=b^=a^=b;

I think *you're* right.

> which still has a number of problems.

Ah, but now I *know* you're right.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

Martin Ambuhl
Guest
Posts: n/a

 06-07-2007
Johan Bengtsson wrote:
> Martin Ambuhl wrote:
>> No, it is horrid. The OP poster asked about swapping two number
>> [sic]. The '^' operator requires operands of an integer type. And
>> that's not all that's wrong with it. This question has been beaten to
>> death before. If you really are committed to the silly XOR trick,
>> check the FAQ and the newsgroup archives to find out why you shouldn't
>> be. You might also find out why, even when the silly XOR trick works,
>> writing it as a single statement is a bad idea.

>
> Not that I think either of those solutions is any good but the original
> problem contained questions of the type "enter a single digit number".

The reference to single digit number does not occur in this question,
which was
> Write a macros in which swap two number without using 3rd variable and
> then call
> Macro in main function.

I understand that intertextuality is all the rage, but it is a severe
error to think that the specification of one problem carries over to a
different, unrelated one.
> I
> personally think integer types is a very good variable type for that.

And that opinion is completely irrelevant to the problam.

> However the original post also states that it needed to be done with a
> macro.

As I pointed out in my initial response
<(E-Mail Removed)> dated Tue, 05 Jun 2007 05:09:22
-0400 in response to "Umesh"'s supposed solution using addition and
subtraction, where I wrote (among other things):
> This is very, very bad.
> 1) Suppose a+b > INT_MAX. What do you think your code will do?
> 2) The OP wrote "Write a macros in which swap two number without using
> 3rd variable". What makes you think all numbers are ints?
> 3) This is not a macro.

There is no normally no need to repeat what has been written before, but
this time I'll make an exception.

> No I am not going to post a solution here either since it so obviously
> is homework, and frankly I don't understand why it wouldn't be allowed
> to use a third variable.

There is no reason, except the (extremely silly) initial problem stated
that as a condition, to which the only correct answer is "Don't do it".