[Ilugc] Re: Re: [C] Swap integers without using temp variable

Binand Sethumadhavan binand at gmail.com
Tue Apr 19 09:30:12 IST 2005


On 19/04/05, Sridharan Anand <sanand at au-kbc.org> wrote:
> > will grok if you call it as swap(v,v).
>                               ^^^^^^^^^
> Just a nit.  You also meant to pass pointers, presumably,
> and to check equivalence inside swap ()?  Then it would grok.

When I typed that, I had in mind a macro-implementation of swap().
Sorry I was not clear.

A function implementation will fail in all cases where the variables
are declared with the "register" storage class (since you cannot have
pointers to them).

> Absolutely.  Totally agree with you here.  You could have said
> `the One True Way of doing it is ...' but that would have started a flame
> war :-D !

"Asking how to swap to variables without using a temporary is like
asking how to drive a nail without using a hammer.  The correct answer
is not "use xor" or "use your forehead", it's "why do you want to do
that?"."

http://groups-beta.google.com/group/comp.lang.c/msg/acd01a7c71add3d6?dmode=source

Binand


More information about the ilugc mailing list