Article View: comp.std.c
Article #1792qsort(), bsearch(), and rude comparison functions
From: Paul Eggert
Date: Sat, 06 Oct 1990 01:34
Date: Sat, 06 Oct 1990 01:34
17 lines
1358 bytes
1358 bytes
Suppose I pass to qsort() a comparison function that isn't a total order. May qsort() dump core? For example, NN 6.4.10 passes the function order_subj_date() to qsort(). This function is not a total order: there are values A,B,C such that A<B, B<C, and C<A according to this function. (This bug is fixed in NN 6.4.11.) SunOS 4.1's qsort() dumps core sometimes in this situation. It seems to me that a conforming qsort() should be allowed to dump core here, but I don't see where the ANSI C standard permits this. While we're on the subject, what happens if the comparison function has side effects, benign or otherwise? How are the sequence points defined here? For example, suppose I qsort() an N-item array using a comparison function that increments a global counter starting at zero; must the counter be at least N-1 when qsort() returns? Similar questions apply to bsearch().
Technical Details
Message-ID:
<1990Oct6.013443.5364@twinsun.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jarthur!ucivax!ucla-cs!twinsun!eggertShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jarthur!ucivax!ucla-cs!twinsun!eggert From: eggert@ata.twinsun.com (Paul Eggert) Newsgroups: comp.std.c Subject: qsort(), bsearch(), and rude comparison functions Message-ID: <1990Oct6.013443.5364@twinsun.com> Date: 6 Oct 90 01:34:43 GMT Sender: news@twinsun.com Organization: Twin Sun, Inc Lines: 17 Originator: eggert@ata Nntp-Posting-Host: ata