[COMMITED][v2] manual: Remove incorrect claim that qsort() can be stabilized
Anders Kaseorg
andersk@mit.edu
Thu Dec 11 09:45:00 GMT 2014
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
More information about the Libc-alpha
mailing list