Article View: comp.std.c
Article #4946Re: Restrictions on qsort compare function?
From: Mark Brader
Date: Sun, 24 Mar 1996 07:13
Date: Sun, 24 Mar 1996 07:13
24 lines
1502 bytes
1502 bytes
> > It would surprise me not at all if qsort() relied on
> ^^^^^^^^^
> > sort_func() having the property that
>
> > !!sort_func(p1, p2) == -1 * !!sort_func(p2, p1)
>
> Of course, in comp.std.c, I should have said "...were permitted to rely on..."
Better yet, you should have not have assumed that !!x would produce -1
when x < 0. <grin>
Incidentally, I have encountered code where the comparison function for
qsort() actually WAS specified with a return expression like *a < *b that
produced 0 when it should have produced -1. The interesting part is that,
on the particular machine the programmer had been using, the sort worked
correctly. Evidently this particular qsort() implementation only tested
whether the comparison function returned a positive value or not.
--
Mark Brader, msb@sq.com, SoftQuad Inc., Toronto
"I'm a little worried about the bug-eater," she said. "We're embedded
in bugs, have you noticed?" -- Niven, "The Integral Trees"
My text in this article is in the public domain.
Technical Details
Message-ID:
<1996Mar24.071329.24975@sq.com>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!torn!sq!msbReferences:
<4iokop$h4p@lyra.csx.cam.ac.uk> <mjs.827419998@hubcap> <mjs.827424727@hubcap>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!howland.reston.ans.net!torn!sq!msb From: msb@sq.com (Mark Brader) Subject: Re: Restrictions on qsort compare function? Message-ID: <1996Mar24.071329.24975@sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <4iokop$h4p@lyra.csx.cam.ac.uk> <mjs.827419998@hubcap> <mjs.827424727@hubcap> Date: Sun, 24 Mar 1996 07:13:29 GMT