🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #2952

Re: qsort() in gcc does not do indirect sorting?

#2952
From: Jeff Urlwin
Date: Sun, 15 Nov 1992 23:01
35 lines
1480 bytes
In article <1e44n6INN49u@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
>In article <1e3ejjINNdf4@pollux.usc.edu> ckhung@pollux.usc.edu (Chao-Kuei Hung) writes:
>:
>:int cmp(const int *i, const int *j)
>:{
>:    return(data[*i].x < data[*j].x ? -1 : 1);
>:}
>
>
>BZZZZZT! How will cmp() ever show that data[*i].x == data[*j].x??
>Your cmp() can never return 0 to show that the two are equal. Perhaps
>this worked on other platforms, because that particular sort didn't
>matter if  a==b. I think the sort is getting into an infinite loop
>because of this.
>
>This works in EMX/GCC:
>
>int
>cmp (const int * i, const int * j)
>{
>	if (data[*i].x == data[*j].x)
>	  return 0;
>	if (data[*i]].x < data[*j].x)
>	  return -1;
>	return 1;
>}

Better yet, 
  return (data[*j].x - data[*i].x);

Jeff

-- 
--------------------------------------
jurlwin@gandalf.umcs.maine.edu
Technical Details
Message-ID: <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!mars.caps.maine.edu!gandalf!jurlwin
References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer,comp.os.os2.apps
Path: arc1-ca.pugleaf.net!sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!mars.caps.maine.edu!gandalf!jurlwin
From: jurlwin@gandalf.UMCS.Maine.EDU (Jeff Urlwin)
Subject: Re: qsort() in gcc does not do indirect sorting?
Message-ID: <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>
Organization: University of Maine, Department of Computer Science
References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca>
Date: Sun, 15 Nov 1992 23:01:07 GMT
Lines: 36