🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4930

Re: Restrictions on qsort compare function?

#4930
From: Christopher R. Volpe
Date: Fri, 22 Mar 1996 16:29
29 lines
1631 bytes
In article <4it51b$ng8@usenet.pa.dec.com>, diamond@tbj.dec.com (Norman Diamond) writes:
|>
|>>>Just one sentence earlier, you gave the exact reason why
|>>>it doesn't matter if you do "a > b" instead of "a - b".
|>
|>>Of course it matters.  With this function, if compar(x,y) > 0, then
|>>compar(y,x) == 0.  This is not antisymmetric.
|>
|>Argh!  I was remembering what the hardware usually does for comparison
|>instructions, and forgot that C operators lose part of that information.
|>I must be getting Cnile.
|>
|>>(a > b)? 1: (a < b)? -1: 0
|>
|>Yup.  Incidentally, do you think the average implementation's
|>interprocedural optimization phase will change this user function into
|>one machine instruction in the library's qsort() function :-?

I'd be quite impressed if it did.

Alternatively, how about this:

    return ((signed int) ((unsigned int)a - (unsigned int)b));

--

Chris Volpe				Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D			Fax:   (518) 387-6560
PO Box 8, Schenectady, NY 12301		Email: volpecr@crd.ge.com
Technical Details
Message-ID: <4iukhc$5nr@rdsunx.crd.ge.com>
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe
From: volpe@bart.crd.ge.com (Christopher R. Volpe)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: 22 Mar 1996 16:29:32 GMT
Organization: GE Corporate Research & Development
Sender: volpe@bart (Christopher R. Volpe)
Distribution: world
Message-ID: <4iukhc$5nr@rdsunx.crd.ge.com>
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com>
Reply-To: volpe@ausable.crd.ge.com
NNTP-Posting-Host: bart.crd.ge.com