Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Summary: A valid criticism Message-ID: <1547@l.cc.purdue.edu> Date: 1 Sep 89 12:47:30 GMT References: <8350@boring.cwi.nl> <10897@smoke.BRL.MIL> Organization: Purdue University Statistics Department Lines: 33 In article <10897@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > In article <1545@l.cc.purdue.edu> cik@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@l.cc.purdue.edu (Internet, bitnet, UUCP)