简体   繁体   English

分配给结构的不兼容指针类型

[英]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 * (aka struct nodeall * ) from Nall *(void) (aka struct 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.

相关问题 在struct中分配内存时类型不兼容 - incompatible types when assigning memory in struct 分配给类型struct时不兼容的类型 - incompatible types when assigning to type struct 分配给类型“struct ListNode”时的类型不兼容 - Incompatible types when assigning to type ‘struct ListNode’ 不兼容的指针类型结构节点到节点 - Incompatible pointer types struct node to node 与typedef和struct不兼容的指针类型警告 - Incompatible pointer types warning with typedef and struct 从 struct 分配给类型 struct * 时的类型不兼容 - incompatible types when assigning to type struct * from struct 警告:不兼容的指针类型从“ mode_t”(又称为“ unsigned int *”)分配给“ node_t *”(也称为“结构节点*”) - Warning: Incompatible pointer types assigning to 'node_t *' (aka 'struct node *') from 'mode_t' (aka 'unsigned int *') 在结构中引用结构会生成“不兼容指针类型”警告 - Referencing struct within a struct generates “incompatible-pointer-types” warnings 从Int类型分配给&#39;struct PartyInfo&#39;类型时不兼容的类型 - Incompatible types when assigning to type 'struct PartyInfo' from type Int 将struct var分配给函数的retval时出现“不兼容的类型” - “Incompatible types” when assigning struct var to retval of function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM