Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <19354@mimsy.UUCP> Date: 31 Aug 89 19:48:10 GMT References: <8350@boring.cwi.nl> <1545@l.cc.purdue.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 20 -In article <14479@haddock.ima.isc.com> karl@haddock.ima.isc.com -(Karl Heuer) writes: ->[The xor trick] won't work on float, pointer, struct, etc. In article <1545@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: -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. And if one uses a wrench as a hammer, it sometimes (actually often) works. If you want to swap values, you should swap values. Icon has a nice notation for it: `x:=:y'. C happens not to have a nice notation for it. (use int) is not very nice either, because it is size dependent. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris