【发布时间】:2021-05-29 13:46:18
【问题描述】:
#include <stdlib.h>
#include <stdio.h>
struct CELL {
char* data;
struct CELL* next;
} ;
struct CELL* table;
// The line below gives an error
table = malloc(SIZE * sizeof(struct HASHCELL));
我正在尝试使用 malloc 创建一个 struct CELL 数组。
但是,这样做会给出“警告:缺少类型说明符,默认为 'int' [-Wimplicit-int]”。因此,它给出了“错误:用不同类型重新定义'table':'int' vs 'struct CELL *”。我是 C 新手,我不确定为什么会这样。
【问题讨论】:
-
你用的是什么编译器?
-
请edit 并显示minimal reproducible example。我试过this code,它编译得很好。
-
@Jabberwocky 这就是我现在所拥有的。感谢您编译它。我不确定为什么它对我不起作用。
-
投票重新打开,以便可以作为副本关闭。 (应该可以选择投票来更改关闭原因。)
-
@Jabberwocky 发生了什么?我们重新打开它,然后作为副本关闭,然后您重新打开它......再次?我很困惑。