我写了比较函数
int cmp(const int * a,const int * b)
{
if (*a==*b)
return 0;
else
if (*a < *b)
return -1;
else
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我有我的声明
int cmp (const int * value1,const int * value2);
Run Code Online (Sandbox Code Playgroud)
我在我的程序中调用qsort就像这样
qsort(currentCases,round,sizeof(int),cmp);
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我收到以下警告
warning: passing argument 4 of ‘qsort’ from incompatible pointer type
/usr/include/stdlib.h:710: note: expected ‘__compar_fn_t’ but argument is of type ‘int
(*)(const int *, const int *)’
Run Code Online (Sandbox Code Playgroud)
该程序工作正常,所以我唯一担心的是为什么它不喜欢我使用它的方式?