Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!brunix!tac From: tac@cs.brown.edu (Theodore A. Camus) Newsgroups: comp.lang.c Subject: Re: Swapping two variables in place Message-ID: <50830@brunix.UUCP> Date: 23 Sep 90 18:29:19 GMT References: <26101@shamash.cdc.com> <26310@cs.yale.edu> Sender: news@brunix.UUCP Reply-To: tac@cs.brown.edu (Theodore A. Camus) Organization: Brown University Department of Computer Science Lines: 22 >There was a message a while back about not being able to create a good >#define function to swap two variables. > >How about this one: #define swap(a,b) a^=b^=a^=b >But it won't work on `float's and `double's, as `^' is defined only on >integral types. Nor would it work for swap(i,A[i]). In fact, the usual { tmp = i ; i = A[i] ; A[i] = tmp } would fail too. Thus the danger of call-by-name. [ref 2nd Dragon book] CSnet: tac@cs.brown.edu Ted Camus ARPAnet: tac%cs.brown.edu@relay.cs.net Box 1910 CS Dept BITnet: tac@browncs.BITNET Brown University "An ounce of example is worth a pound of theory." Providence, RI 02912