swap(x,y)

Herman Rubin cik at l.cc.purdue.edu
Fri Sep 1 00:29:05 AEST 1989


In article <14479 at haddock.ima.isc.com>, karl at haddock.ima.isc.com (Karl Heuer) writes:
> In article <230 at crdos1.crd.ge.COM> davidsen at 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 at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list