Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Sep 2002 11:30:03 -0700 (PDT)
From:      "Jin Guojun [DSD]" <j_guojun@lbl.gov>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/42818: qsort can only sort up to 6 element for structure
Message-ID:  <200209161830.g8GIU3YE013033@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/42818; it has been noted by GNATS.

From: "Jin Guojun [DSD]" <j_guojun@lbl.gov>
To: Gregory Bond <gnb@itga.com.au>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/42818: qsort can only sort up to 6 element for structure
Date: Mon, 16 Sep 2002 11:26:29 -0700

 My fault -- I typed a wrong operator "<". It supposes to be "-". So, the correct
 operation
 is:
 
 int   smaller(const void *i1, const void *i2)
 {
     return    *(int*)i1 - *(int*)i2;
 }
 
 Thanks,
 
     -Jin
 
 Gregory Bond wrote:
 
 > The bug is in your program.  To quote qsort(3):
 >
 >      The comparison function must return an integer less than, equal to, or
 >      greater than zero if the first argument is considered to be respectively
 >      less than, equal to, or greater than the second.
 >
 > Your comparison function returns 0 or 1 only.  Perhaps you are being confused
 > by the C++/STL comparison objects?
 >
 > Modifying your comparison fn to the following makes it work:
 >         int
 >         smaller(const void *i1, const void *i2)
 >         {
 >                 if (*(int*)i1 < *(int*)i2) return -1;
 >                 return  *(int*)i1 > *(int*)i2;
 >         }
 >
 > The fact that your test program seems to work for these test cases on Solaris
 > and Linux is a simple coincidence, and depends on fine internal details of the
 > sort algorithm on those systems.  There will probably be other cases where the
 > Linux/Solaris qsort() will also fail.
 >
 > This PR can be closed.
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209161830.g8GIU3YE013033>