[英]implicit declaration of function free is invalid in c99
In xcode 5 I get this warning: 在xcode 5中,我收到此警告:
"implicit declaration of function free is invalid in c99"
“c99中隐式声明函数无效”
How should I free my c structures if I can't use the function free()? 如果我不能使用free()函数,我应该如何释放我的c结构?
你应该包括<stdlib.h>
。
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 . 要确定哪个标头包含原型,请尝试搜索“man free”并查找Linux手册页 。 Close to the top, it says:
靠近顶部,它说:
#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. 到你的源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.