swap(x,y)

Norman Diamond diamond at csl.sony.co.jp
Mon Sep 4 16:04:04 AEST 1989


In article <1545 at l.cc.purdue.edu> cik at 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 at 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.



More information about the Comp.lang.c mailing list