I did not find anything about this on the man page, but cppreference.com says:
The signature of the comparison function should be equivalent to the following:
int cmp(const void *a, const void *b);The function must not modify the objects passed to it and must return consistent results when called for the same objects, regardless of their positions in the array.
Would converting the strings with strtod, atof etc. come under modification and result in undefined behavior or so?
The objective is to sort an array of char * numerically. If it is illegal, do I have to write my own sort routine?
Converting the strings pointed to by the array elements using
strtodoratofis perfectly fine because neither of these functions modify their argument strings. Note that the comparison function arguments of typeconst void *do not point to the strings in your example, they point to individualchar *elements of the array, which it must not change. What thesechar *pointers point to should not be changed either as this might affect the result of further comparisons involving the same string pointers, producing inconsistent results, hence causing undefined behavior inqsort.Here is an example: