Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > PLEASE HELP ME ! PLEASE

Thread Tools


Richard Heathfield
Posts: n/a
Keith Thompson said:

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


>> 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
email: rjh at the above domain, - www.
Reply With Quote
Martin Ambuhl
Posts: n/a
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".

Reply With Quote

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Please please please help this guy with his open source java app Java 4 05-05-2005 08:24 AM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM