如何在编译器检查以确保参数传递是指针指针时正确消除此警告?消除void **与any_struct_t **警告
void somefunc (void **elements)
{
// This function works on any array type
// Maybe it prints pointer addresses
void **pp;
for (pp = elements; *pp; pp ++)
printf ("address: %x\n", *pp);
}
int main (const char *cmdline)
{
typedef struct {
int a, b, c;
} any_struct_t;
any_struct_t *group[25] = {0}; // (any_struct_t **)
group[0] = malloc (sizeof(any_struct_t));
somefunc(group); // <--- WARNING (any_struct_t **) vs. (void **)
getchar();
exit (0);
}
是否有“双空”类型的指针或可在这里用来得到正确消除这个警告的一些超级晦涩Ç招:
I want this warning to go away via code:
warning: passing argument 1 of 'somefunc' from incompatible pointer type
expected 'void **' but argument is of type 'any_struct_t **'
函数想要一个指向指针的指针,它不关心它是什么类型的指针。
我可以通过强制转换(void *)来消除警告,但编译器不再检查它是否是指向指针的指针。
是什么原因,为什么你有一个指针数组,每个指针指向到一个单一的结构?是否有一个原因,你为什么不能有一个结构数组呢? – Lundin
编译器无论如何都没有真正检查指向指针的指针。 – Peter
有没有办法让它这样做? –