This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [COMMITED][v2] manual: Remove incorrect claim that qsort() can be stabilized
- From: Anders Kaseorg <andersk at mit dot edu>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Paul Eggert <eggert at cs dot ucla dot edu>, OndÅej BÃlka <neleai at seznam dot cz>, Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Thu, 11 Dec 2014 04:44:53 -0500 (EST)
- Subject: Re: [COMMITED][v2] manual: Remove incorrect claim that qsort() can be stabilized
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1407022115210 dot 28890 at all-night-tool dot MIT dot EDU> <20141210154909 dot GA31968 at domone> <54892DF9 dot 8080007 at cs dot ucla dot edu> <mvmmw6ur0d5 dot fsf at hawking dot suse dot de>
On Thu, 11 Dec 2014, Andreas Schwab wrote:
> Paul Eggert <eggert@cs.ucla.edu> writes:
>
> > The last clause is incorrect. C11 and POSIX both require that the
> > addresses passed to the comparison function must point to elements of the
> > original array, and glibc qsort conforms to the standards here.
>
> That is only true for bsearch:
>
> "The comparison function pointed to by compar is called with two
> arguments that point to the key object and to an array element, in
> that order."
>
> The description for qsort does not say that:
>
> "The contents of the array are sorted into ascending order according
> to a comparison function pointed to by compar, which is called with
> two arguments that point to the objects being compared."
No, Paul is right, see C99 Â7.20.5/C11 Â7.22.5, outside of the main
description for qsort:
âThe implementation shall ensure that the second argument of the
comparison function (when called from bsearch), or both arguments (when
called from qsort), are pointers to elements of the array.â
Anders