[comp.lang.c] Aaagh! Not swap macros again!

jas@llama.rtech.UUCP (Jim Shankland) (01/20/88)

In article <3887@sigi.Colorado.EDU> swarbric@tramp.Colorado.EDU (SWARBRICK FRANCIS JOHN) writes:
>#define swap(a,b) ((a) = ((b) = ((a) = (a) ^ (b)) ^ (b)) ^ (a))
>
>Try that, and tell me what you think.  A super-genius friend of mine figured
>it out.  He says it will work for anything (int, char *, etc.).  But it
>sure boggles my mind...

It will work if and only if a and b are of integral type (char, short, int,
long, and unsigned variants thereof), and are not aliases for the same
object.  [Nasty remark containing the word "super-genius" deleted.]

We did, indeed, go over this not long ago.  Personally, I won't be too
upset if we don't go over it again.

Jim Shankland
  ..!ihnp4!cpsc6a!\
               sun!rtech!jas
 ..!ucbvax!mtxinu!/