【发布时间】:2014-02-07 16:42:34
【问题描述】:
我正在开发一个项目,其中我有一个定义 list 和 list_elem 结构的标题,很像实际的 c 库(列表的实现没有错误)。我正在编写一个使用列表实现的源文件,我收到以下警告:
warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
这是list_elem结构的声明
/* List element. */
struct list_elem
{
struct list_elem *prev; /* Previous list element. */
struct list_elem *next; /* Next list element. */
};
我在这里使用的:
//creates a list element
struct list_elem le_current;
&le_current = (struct list_elem *)malloc(sizeof(struct list_elem));
我知道另一个问题与相同的问题,但与那个人不同,我确实包括了
#include <stdlib.h>
还有定义列表的标题
#include "lib/kernel/list.h"
【问题讨论】:
-
感兴趣的可能是“不要强制转换 malloc 线程”-stackoverflow.com/questions/605845/…
-
不要强制转换 malloc
-
隐式声明意味着编译器没有看到
malloc的声明...stdlib.hdefo 是否包含在此语句之前? (我知道你说过你做了,但可能值得仔细检查)。 -
肯定 "&le_current" 在作业的左侧无效?我怀疑发生的事情比我们被告知/展示的要多。
-
le_current需要mallocing 吗?
标签: c list struct malloc sizeof