Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.co.jp (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <10790@riks.csl.sony.co.jp> Date: 4 Sep 89 06:04:04 GMT References: <8350@boring.cwi.nl> <14479@haddock.ima.isc.com> <1545@l.cc.purdue.edu> Reply-To: diamond@riks. (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 26 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 [the XOR trick] >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. The way to write this pseudo-op in C is: *(int*)&x It still doesn't work if x is longer than an int. Most hardware does not supply tools for performing XOR on floating-point registers. When Mr. Rubin designs his language, he will have to design a machine to run it on too. -- -- Norman Diamond, Sony Corporation (diamond@ws.sony.junet) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.