好的,所以我有以下结构
struct node { int visited; struct node **depend; };
我试图使用以下动态分配它
fscanf(iStream, "%d %d", &nTasks, &nRules); graph = (struct node *) malloc(nTasks * sizeof(struct node));
但Eclipse显示了一个
..\GraphSort.c:62:18:警告:隐式声明函数'malloc'[-Wimplicit-function-declaration] graph =(struct node*)malloc(nTasks*sizeof(struct node)); ^
和
..\GraphSort.c:62:26:警告:内置函数'malloc'的不兼容隐式声明[默认启用] graph =(struct node*)malloc(nTasks*sizeof(struct node)); ^
我不明白的是为什么.不是表示为第一个元素的指针的数组吗?
还有一点,我有这个声明,没有显示任何警告
fscanf(iStream, "%d, %d", &taskId, &dependencies); graph[taskId-1].visited = 0; graph[taskId-1].depend = (struct node **) malloc(dependencies * sizeof(struct node *));
Tim Pierce.. 5
implicit declaration of function 'malloc'
表示您没有包含正确的头文件,告诉您的程序如何调用malloc
.尝试添加到程序的开头:
#include
你的其他代码不是"声明",它只是一系列声明.编译器只会警告您未能malloc()
为其编译的每个文件声明.