Bug in users command

Lars Henrik Mathiesen thorinn at diku.dk
Mon Jan 21 06:05:43 AEST 1991


brnstnd at 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 at diku.dk



More information about the Comp.bugs.4bsd.ucb-fixes mailing list