Glibc qsort_r takes the 'thunk' parameter in a different argument, and
passes 'thunk' in a different argument to the comparator. This allows
qsort and qsort_r to share an implementation on common architectures,
where the bogus 3rd argument is mostly free and ignored. Also, support
Linux-originated programs and libraries in a straightforward way.
Backwards compatibility for old programs is provided using the GCC
extension __builtin_choose_expr, which Clang supports.
(It seems like C11 _Generic() should support this; however, it
explicitly does not support 'function' types, and it seems that
'function' and 'function pointer' types are incompatible for its
purposes, at least in Clang. Requiring qsort_r(a,b,c,&cmp,t) seems much
less useful to me. Additionally, a few other hacks were explored and
nothing panned out quite as well as using the GCC extension. See the