A generic sorting routine.
This an implementation of the qsort
variant as it is specified in Annex K of the C11 standard. Its particularity is that it additionally takes a "context" argument, which allows to program comparison functions more widely, without refering to global variables. Its prototype if it were not implemented as a type generic macro, would be:
int (*compar)(const void *x, const void *y, void *context),
void *context);
Because this is a type generic macro, the implementation can take care of the "real" base type of base
, in particular about alignment. If it really only would receive a void*
it would have to make the worst assumptions about that and always use memcpy
to copy elements around. If it has more type information it can use more efficient means for that. So casting the first argument to void*
wouldn't be a good idea.
Definition at line 496 of file p99_qsort.h.