tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: qsort_r
On Mon, Dec 09, 2013 at 06:10:36AM +0000, Alan Barrett wrote:
> >My irritation with not being able to pass a data pointer through
> >qsort() boiled over just now. Apparently Linux and/or GNU has a
> >qsort_r() that supports this; so, following is a patch that gives
> >us a compatible qsort_r() plus mergesort_r(), and heapsort_r().
>
> Apparently FreeBSD [1] and GNU [2] have incompatible versions of
> qsort_r, passing the extra 'thunk' or 'data' argument in a
> different position.
>
> [1]: FreeBSD qsort_r <http://www.manpagez.com/man/3/qsort_r/>
> [2]: Linux qsort_r <http://man7.org/linux/man-pages/man3/qsort.3.html>
>
> If we have to pick one, let's pick the FreeBSD version.
Given that it's just left vs. right side, the only technical reason to
favor one over the other is that the right-side one (the Linux one)
allows sharing the same object code for both versions, at least on
common platforms, as discussed elsewhere in this thread.
Also, all else being equal the Linux one de facto has greater market
penetration.
So I think picking the Linux one is a marginally better choice.
> >Note that the thunks use an extra struct to hold the function
> >pointer; this is to satisfy C standards pedantry about void
> >pointers vs. function pointers, and if we decide not to care it
> >could be simplified.
>
> That adds more run-time overhead. Could you make it conditional on
> whether it's really necessary? All existing NetBSD platforms can
> convert back and forth between void * and function pointers without
> any trouble.
I think switching approaches (as in the other post I just made) is
probably a better idea, because it also gets rid of this issue.
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index