c - Malloc 指针数组错误

标签 c arrays pointers memory-management malloc

我有以下代码:

    interface ** rInterfaces[MAX_REACTANS];
    _reaction->rInterfaces = (interface **)malloc(MAX_REACTANS * sizeof(interface *));

我收到一条错误消息:

error: incompatible types when assigning to type ‘struct interface **[10]’ from type ‘struct interface **’

我不知道为什么我会得到这个。任何帮助将不胜感激。

最佳答案

根据您的 malloc 判断,您需要一个指向接口(interface)的指针。从声明中删除 [MAX_REACTANS]。您还可以删除 interface ** cast。

关于c - Malloc 指针数组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9422916/

相关文章:

c - C 中数组的动态分配

c - 堆栈 'CSTACK' 的堆栈指针超出堆栈范围

c - semaphore.h 中信号量的 pthread API 等效项

c++ - 有没有办法禁止在 c 样式变量参数列表中按值使用类?

javascript - Angularjs 轮询 API 检查 JSON 中的空数组

arrays - 元组/数组对列表

C 代码编译没有错误但不能正确运行(命令行参数和指针)

c - 使用 char 指针声明的字符串的内存地址

PHP循环遍历月份数组

c++ - 如何将指针的元素更改为 vector ?