qsort sorts an array through a caller-provided comparison function. It accepts the array base as a void pointer, the element count, the element size, and a comparator, allowing one interface to handle many data types. section 11.4
Use the interface correctly by preserving the comparator contract:
- Pass the address of the first element, the number of elements, and the size of each element. section 11.4
- Write a comparator receiving two const void pointers and returning a negative value, zero, or a positive value for less-than, equality, or greater-than. section 11.4
- Compare values consistently after converting the void pointers to the array’s element type; do not implement integer ordering by subtracting values, because the subtraction may overflow. section 11.4
Sorting unsigned values
A type-specific wrapper can call qsort(base, nmeb, sizeof base[0], compare_unsigned), while compare_unsigned casts its arguments to unsigned pointers and returns -1, 0, or +1 through explicit comparisons.

