相关疑难解决方法(0)

在C中使用qsort时出现警告

我写了比较函数

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)

该程序工作正常,所以我唯一担心的是为什么它不喜欢我使用它的方式?

c qsort

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

qsort ×1