🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4925

Re: Restrictions on qsort compare function?

#4925
From: Roger Wells
Date: Thu, 21 Mar 1996 17:00
24 lines
1501 bytes
In article <4iqjar$2m9@usenet.pa.dec.com>, diamond@tbj.dec.com (Norman Diamond) writes:
>In article <4iokop$h4p@lyra.csx.cam.ac.uk>, jkb@mrc-lmb.cam.ac.uk (James Bonfield) writes:
>>Are there any limitations on what the sort function passed over to qsort can
>>do or return?
>
>>I know it's meant to return < 0, 0 or > 0 for the various compare operations,
>>but which you return is purely up to your own comparison system.
>
>Exactly.
>
>>On tracking down a bug in some old code I noticed that we had the
>>compare function returning something like "a > b" instead of "b - a".
>>Now this is obviously some silly bug in our coding,
>
>Actually it's a silly question.  Just one sentence earlier, you gave the
>exact reason why it doesn't matter if you do "a > b" instead of "a - b".

The expression a > b can only have the values 0 or 1; therefore, if your
qsort comparison returns a > b it will never return a negative value.  If
a is less than b, it will return 0, which to qsort means they are equal.  I
do not believe that is what you want.

--
Roger Wells (speaking only for myself)
Technical Details
Message-ID: <4is1vu$5et@news1.halcyon.com>
Path: arc1-ca.pugleaf.net!usin.com!rwells
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!usin.com!rwells
From: rwells@usin.com (Roger Wells)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: 21 Mar 1996 17:00:46 GMT
Organization: U.S. Intelco Networks, Inc.
Distribution: world
Message-ID: <4is1vu$5et@news1.halcyon.com>
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com>
NNTP-Posting-Host: 198.202.216.7