关于malloc结构数组的困惑

 郑小斌-杭州 发布于 2023-02-11 11:28

好的,所以我有以下结构

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()为其编译的每个文件声明.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有