This is the mail archive of the mailing list for the newlib 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: How to implement qsort_r

On 12/04/2014 10:11 AM, Yaakov Selkowitz wrote:
>> My personal preference is the glibc style (the opaque argument last in
>> both qsort_r and the comparator), not the BSD style (the opaque argument
>> first in both calls),  This is because POSIX already has other
>> standardized functions in the glibc style (pthread_cleanup_push,
>> pthread_create), and none in the BSD styloe.
> Generally I would agree, but wouldn't it make more sense to group
> together the arguments to compar, IOW:
> void qsort_r(void *base, size_t nmemb, size_t size, void *arg, int
> (*compar)(const void *, const void *, void *));

No - I generally see code doing 'callback, opaque' and expecting a call
to callback(other args..., opaque).  What you've written here matches
neither BSD nor glibc, and does NOT preserve the pthread_create
precedent of 'callback, opaque' turning into a call to callback(...,

BSD was at least consistent in having 'opaque, callback' turn into
'callback(opaque, ...)' (opaque always first), but as Corinna points
out, this form is not shim-able, while glibc's opaque-last is.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

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