C语言 函数 free 的隐式声明在 c99 中无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19401658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
implicit declaration of function free is invalid in c99
提问by chrs
In xcode 5 I get this warning:
在 xcode 5 中,我收到此警告:
"implicit declaration of function free is invalid in c99"
“函数 free 的隐式声明在 c99 中无效”
How should I free my c structures if I can't use the function free()?
如果我不能使用函数 free(),我应该如何释放我的 c 结构?
回答by Some programmer dude
You should include <stdlib.h>.
你应该包括<stdlib.h>.
回答by unwind
You get that warning because you're calling a function without first declaring it, so the compiler doesn't know about the function.
您收到该警告是因为您在未先声明的情况下调用了一个函数,因此编译器不知道该函数。
All functions need to be declared before being called, there are no "built-in" functions in C.
所有函数都需要在调用之前声明,C 中没有“内置”函数。
It's true that free()is a function defined in the standard, but it's still not built-in, you must have a prototype for it.
确实free()是标准中定义的函数,但它仍然不是内置的,你必须有它的原型。
To figure out which header has the prototype, try searching for "man free" and look for a Linux manual page. Close to the top, it says:
要找出哪个头文件具有原型,请尝试搜索“man free”并查找Linux 手册页。靠近顶部,它说:
#include <stdlib.h>
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
This tells you that in order to use the listed functions, you should add:
这告诉您,为了使用列出的函数,您应该添加:
#include <stdlib.h>
to your source code.
到您的源代码。

