[英]Incompatible pointer types assigning to struct
I'm just trying to make some kind of pointer to "Nall" struct so I wrote this code我只是想制作某种指向“Nall”结构的指针,所以我写了这段代码
Nall **headall;
headall = malloc (30000 * sizeof (Nall));
for (i = 0; i < 30000; i++) {
*(headall+i) = newNall;
}
and now I get this error现在我收到这个错误
"warning: incompatible pointer types assigning to
Nall *
(akastruct nodeall *
) fromNall *(void)
(akastruct nodeall *(void)
) [-Wincompatible-pointer-types]*(headall+i) = newNall;
"“警告:从
Nall *(void)
(又名struct nodeall *(void)
)[-Wincompatible-pointer-types]*(headall+i) = newNall;
分配给Nall *
(又名struct nodeall *
)的不兼容指针类型*(headall+i) = newNall;
“
From the compiler warning I'm assuming that newNall
is actually a function that allocates a new struct nodeall
and returns a pointer to it.从编译器警告中,我假设
newNall
实际上是一个分配新struct nodeall
并返回指向它的指针的函数。 In that case, your code should look like this:在这种情况下,您的代码应如下所示:
Nall **headall;
headall = malloc(30000 * sizeof *headall);
for (i = 0; i < 30000; i++)
headall[i] = newNall();
Note the argument to the sizeof
operator, and the parentheses after newNall
.请注意
sizeof
运算符的参数以及newNall
之后的括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.