[comp.sys.sun] qsort mistakes in 4.0

forsyth@minster.york.ac.uk (12/20/89)

Someone added a little example to the manual page for qsort between 3.5
and 4.0.  unfortunately, it is wrong in every important aspect if one is
concerned about portability:

	- the comparison function must be declared to take
	  char * pointers (`const void *' in ansi):
		int compar(a, b)
		char *a, *b;
		{
			return *(int *)a - *(int *)b;
		}

	- the array must be cast to char * (or void *):
		qsort((char *)a, ... );

the example as shown will often fail on machines that have different
representations for word and character pointers (for instance).  it is not
type correct.  bsearch(3), and perhaps others, suffers from the same
fault.