This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [COMMITED][v2] manual: Remove incorrect claim that qsort() can be stabilized


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]