Johan said:
Martin said:
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
<
[email protected]> 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".