Path: utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!dkuug!diku!thorinn From: thorinn@diku.dk (Lars Henrik Mathiesen) Newsgroups: comp.bugs.4bsd Subject: Re: Bug in users command Message-ID: <1991Jan20.190543.17142@odin.diku.dk> Date: 20 Jan 91 19:05:43 GMT References: <18958@rpp386.cactus.org> <18928:Jan1916:26:3291@kramden.acf.nyu.edu> <18965@rpp386.cactus.org> <24748:Jan2016:53:4291@kramden.acf.nyu.edu> Sender: news@odin.diku.dk (Netnews System) Organization: Department of Computer Science, U of Copenhagen Lines: 23 brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >Of course, most implementations use the same type for all pointers >internally. But what would happen on a machine where pointers to words >are stored differently (say as the number of bytes divided by 4) while >pointers to characters are stored as byte indices? Then scmp() will >treat its arguments as byte indices, when in fact they could be a factor >of 4 off. Actually, scmp() is called by qsort(), so it will be called with (char *) arguments. But the argument to qsort() should be cast to (char *) to avoid problems on such machines. In ANSI C, scmp() should be declared with (void *) arguments. Then if prototypes for qsort and strcmp are in scope, everything should work out. (Argument: a pointer to an array and a pointer to its first element must give the same result when cast to void pointers, otherwise fwrite() etc. won't work. So casting from "pointer to array of char" to "pointer to void" to "pointer to char" must give a pointer to the first char in the array.) -- Lars Mathiesen, DIKU, U of Copenhagen, Denmark [uunet!]mcsun!diku!thorinn Institute of Datalogy -- we're scientists, not engineers. thorinn@diku.dk