什么是该C qsort函数调用的参数? [英] What are the parameters in this C qsort function call?
问题描述
的qsort(BT-GT&; RW [T],BT-GT&; NUM [T]
的sizeof(TRELLIS_ATOM *)
(INT(*)(常量无效*,常量无效*))compare_wid);
BT-> RW [T]
是结构指针的指针, BT-> [NUM]
是 INT
,我不明白,第四个参数是什么,除了compare_wid是某处定义的函数如下:
静态INT compare_wid(TRELLIS_ATOM *一,TRELLIS_ATOM * B)
{
...
返回X;
}
(INT(*)(常量无效*,常量无效*))
表示善待接下来作为一个指向一个类型常量无效*
的两个参数,并返回一个 INT
的功能。 compare_wid
确实可以用这种方法处理的功能。
的qsort
将调用此函数排序时项目之间执行比较:如果它返回整数是零,则这些项被假定为相等,在其他方面的符号整数用来订购。
qsort(bt->rw[t], bt->num[t],
sizeof(TRELLIS_ATOM *),
(int (*)(const void *,const void *))compare_wid);
bt->rw[t]
is a pointer to struct pointer, bt->[num]
is an int
, I don't understand what that fourth parameter is, except that compare_wid is a function defined somewhere as follows:
static int compare_wid( TRELLIS_ATOM* a, TRELLIS_ATOM* b )
{
...
return x;
}
(int (*)(const void *,const void *))
means "treat what follows as a pointer to a function that takes two parameters of type const void*
and returns an int
". compare_wid
is indeed a function that can be treated this way.
qsort
will call this function to perform comparisons between items when sorting: if the integer it returns is zero, the items are assumed to be equal, otherwise the sign of the integer is used to order them.
这篇关于什么是该C qsort函数调用的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!