swap(x,y)

Herman Rubin cik at l.cc.purdue.edu
Fri Sep 1 22:47:30 AEST 1989


In article <10897 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
> In article <1545 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
> >... so that (use int)x means treat x as type int no matter what it was,
> 
> If it wasn't represented with the same number of bits as an int, what
> could this possibly mean?  If you're going to invent something, make
> sure that it is sufficiently useful first.

This is absolutely correct.  In my earlier posting, I did say that if
the conventions were extended to multi-"word" items, it could be use
for doubles and structs.  And if the exclusive or instruction (or in
those posters who posted it with + and - the arithmetic instructions)
do not involve the whole word, it will not work, even for those items.

To use these devices to swap items, it is necessary to know that they
work on the whole item.  This is not always so, and, for example, using
+ and - will not work on the CYBER 205/ETA 10 machine.

> >This is another example of keeping the tools from the programmer.
> 
> No, this is another example of not knowing how to use the tools that are
> already provided.

All tools must be used with care.  If the items being swapped overlap, there
are great difficulties with the whole process.  If the items are identical,
these procedures definitely give the wrong answer.

Thou shalt know thy computer's hardware idiosyncracies, lest thou mess up
thy results.
-- 
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