Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Summary: With a simple extension, for any type. Message-ID: <1545@l.cc.purdue.edu> Date: 31 Aug 89 14:29:05 GMT References: <8350@boring.cwi.nl> <14479@haddock.ima.isc.com> Organization: Purdue University Statistics Department Lines: 18 In article <14479@haddock.ima.isc.com>, karl@haddock.ima.isc.com (Karl Heuer) writes: > In article <230@crdos1.crd.ge.COM> davidsen@crdos1.UUCP (bill davidsen) writes: > >However, there are reasons for doing tricks such as the XOR thing. They > >enable me to write a macro which does the swap for any type. > > Only for integral types. It won't work on float, pointer, struct, etc. If one adds a pseudo-op, say use (I will not object to a more appropriate term) so that (use int)x means treat x as type int no matter what it was, if possible, then it will work on float and pointer, and even swap between, say, float and pointer. If this is modified to allow multiple-word types, it could handle double and struct. This is another example of keeping the tools from the programmer. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)