🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #13330

qsort mistakes in 4.0

#13330
From: forsyth
Date: Wed, 20 Dec 1989 13:21
19 lines
1109 bytes
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.
Technical Details
Message-ID: <4004@brazos.Rice.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!mit-eddie!uw-beaver!rice!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!mit-eddie!uw-beaver!rice!sun-spots-request
From: forsyth@minster.york.ac.uk
Newsgroups: comp.sys.sun
Subject: qsort mistakes in 4.0
Keywords: SunOS
Message-ID: <4004@brazos.Rice.edu>
Date: 20 Dec 89 13:21:46 GMT
Sender: root@rice.edu
Organization: Sun-Spots
Lines: 19
Approved: Sun-Spots@rice.edu
X-Sun-Spots-Digest: Volume 8, Issue 228, message 16 of 18