我有scandir()的问题:联机帮助页包含这个原型:
int scandir(const char *dir, struct dirent ***namelist,
int (*filter)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
Run Code Online (Sandbox Code Playgroud)
所以我有这个:
static inline int
RubyCompare(const struct dirent **a,
const struct dirent **b)
{
return(strcmp((*a)->d_name, (*b)->d_name));
}
Run Code Online (Sandbox Code Playgroud)
这是电话:
num = scandir(buf, &entries, NULL, RubyCompare);
Run Code Online (Sandbox Code Playgroud)
最后,编译器说:
warning: passing argument 4 of ‘scandir’ from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)
编译器是gcc-4.3.2,我的CFLAGS如下:
-Wall -Wpointer-arith -Wstrict-prototypes -Wunused -Wshadow -std=gnu99
Run Code Online (Sandbox Code Playgroud)
这个警告是什么意思?RubyCompare的声明看起来对我来说是正确的,除了警告代码完全可行.
我将Ruby嵌入到我的C项目中,并希望加载几个定义从我自己的父类继承的类的文件.每个继承的类都需要在初始化时设置一些变量,我不希望Ruby和C有两个不同的变量.
有没有办法定义一个具有自己的自定义setter/getter的类变量,或者这是一种处理它的愚蠢方法?使用自定义数据类型可能会更好吗?