Can the qsort comparison function always return a non-zero value?
问题 An ascending sort callback function for qsort and bsearch on an array of int could look like this: int ascending(const void *o1, const void *o2) { int a = *(const int *)o1; int b = *(const int *)o2; return a < b ? -1 : 1; } Yet this function seems to violate the constraint on the compar function as specified in the C Standard: 7.22.5.2 The qsort function Synopsis #include <stdlib.h> void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); Description The