swap(x,y)

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Aug 23 14:31:41 AEST 1989


In article <MYwDEFy00WB842JEUx at andrew.cmu.edu> tg1e+ at andrew.cmu.edu (Timothy R. Gottschalk) writes:
>       x += y;
>       y = x - y;
>       x -= y;

This is an old trick (usually done using XOR instead of + and -).  Your
version can fail if arithmetic overflow occurs.



More information about the Comp.lang.c mailing list