内置函数“malloc”的隐式声明

时间:2021-10-30 06:58:11

I'm getting this error:

我得到这个错误:

warning: incompatible implicit declaration of built-in function ‘malloc’

警告:内置函数“malloc”的不兼容隐式声明

I am trying to do this:

我试着这么做:

fileinfo_list* tempList = malloc(sizeof(fileinfo_list));

Just for the reference the struct used at hand is:

仅供参考,目前使用的结构是:

typedef struct {
    fileinfo** filedata;
    size_t nFiles;
    size_t size;
    size_t fileblock;
} fileinfo_list;

I don't see anything wrong with what I've done. I'm just creating a tempList with the size of 1 x fileinfo_list.

我不认为我做的有什么不对。我正在创建一个大小为1 x fileinfo_list的tempList。

5 个解决方案

#1


286  

You likely forgot to include <stdlib.h>.

您可能忘记包含

#2


39  

You need to #include <stdlib.h>. Otherwise it's defined as int malloc() which is incompatible with the built-in type void *malloc(size_t).

您需要#include 。否则定义为int malloc(),它与内置类型void *malloc(size_t)不兼容。

#3


14  

You're missing #include <stdlib.h>.

你失踪的# include < stdlib.h >。

#4


3  

The stdlib.h file contains the header information or prototype of the malloc, calloc, realloc and free functions.

stdlib。h文件包含malloc、calloc、realloc和free函数的头信息或原型。

So to avoid this warning in ANSI C, you should include the stdlib header file.

因此,为了避免在ANSI C中出现这种警告,您应该包含stdlib头文件。

#5


-4  

The only solution for such warnings is to include stdlib.h in the program.

这种警告的唯一解决方案是包含stdlib。h的计划。

#1


286  

You likely forgot to include <stdlib.h>.

您可能忘记包含

#2


39  

You need to #include <stdlib.h>. Otherwise it's defined as int malloc() which is incompatible with the built-in type void *malloc(size_t).

您需要#include 。否则定义为int malloc(),它与内置类型void *malloc(size_t)不兼容。

#3


14  

You're missing #include <stdlib.h>.

你失踪的# include < stdlib.h >。

#4


3  

The stdlib.h file contains the header information or prototype of the malloc, calloc, realloc and free functions.

stdlib。h文件包含malloc、calloc、realloc和free函数的头信息或原型。

So to avoid this warning in ANSI C, you should include the stdlib header file.

因此,为了避免在ANSI C中出现这种警告,您应该包含stdlib头文件。

#5


-4  

The only solution for such warnings is to include stdlib.h in the program.

这种警告的唯一解决方案是包含stdlib。h的计划。