Re: Swapping Bull***

From: Gordon Burditt (gordonb.s0bc9_at_burditt.org)
Date: 06/28/04


Date: 28 Jun 2004 05:26:20 GMT


>Am I the only person here that thinks it's complete bull*** to think you
>can swap the values of two variables without a temporary variable?! It

You can, for certain variable types. But the bull*** I see most
often related to this topic is a claim that swapping the values of
two values without a temporary variable is in some way FASTER
(usually such a claim is made in a platform-independent manner. A
claim that B is faster than or slower than or about as fast as C
is usually false when the platform is not specified (and I'm not
even sure about the case where C is "execute B one billion times").),
CLEARER, or BETTER.

>simply cannot be done. Why? Consider this, you have two containers, each of
>capacity 3 litres. Each of them is filled with 2 litres of water. Swap the
>water from the containers. Okay... let's just poor all of one of them into
>the other. Mammy mammy! It was an accident, I didn't realize you can't put 4
>litres of water into a 3 litre container.

Unsigned int variables have better-defined overflow characteristics than
hypothetical water-bucket variables.

                                                Gordon L. Burditt