I'm trying to use the c-lib function qsort() to sort an array of longs. I do it as follows:
int
compar(long *e1, long *e2) // for decreasing order
{
if (*e1 > *e2) return -1;
if (*e1 < *e2) return 1;
return 0;
}
void
c_lib_quick_sort(long *a, long n)
{
qsort(a, n, sizeof(long), compar);
}
The code works perfectly, but clang produces the following warning
sort_timings.c:262:30: warning: incompatible function pointer types passing 'int (long *, long *)' to parameter of type 'int (* _Nonnull)(const void *, const vo
id *)' [-Wincompatible-function-pointer-types]
qsort(a, n, sizeof(long), compar);
^~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h:161:22: note: passing argument to parameter '__compar' here
int (* _Nonnull __compar)(const void *, const void *));
Can someone show me how to eliminate the warning? The warning refers to things like (* _Nonnull), which I've never seen before.
I wrote similar code 15 years ago, but gcc at the time did not produce any warnings. The newer compilers are more strict about types.