随手几行测试代码,编译居然报了一排warning,仔细查看,都是类似如下格式的:
Bash
xxx\xx.c||In function 'xxx':|
xxx\xx.c|14|warning: implicit declaration of function 'memset' [-Wimplicit-function-declaration]|
xxx\xx.c|14|warning: incompatible implicit declaration of built-in function 'memset' [enabled by default]|文件大致是如下的:
C
#ifndef __MAIN_H__
#define __MAIN_H__
#include
// ... sth else
#endif // __MAIN_H__C
#include "main.h"
#include
int main(void)
{
char code[41];
// ... sth else
memset((void *)code,0,41);
// .......
return 0;
}一种解决
stackoverflow 有人出现同样的warning,解决方法就是在前面加个函数声明即可。不过和自己的代码对比了下,看起来只是警告提示相同而已。
我的解决
再翻了一下,找到了这么一段话:It seems that your header files have no prototype declared for some of the functions, so the function itself is implicitly treated as the function prototype. It's actually only a warning, and depending on your compilation flags it should compile even so, so it's no reason to panic. Then again, it shouldn't be a big task to add the prototype to one of your headers or at least add on top of the same source file.memset函数是头文件string.h中的,虽然在main.h中已经声明了string.h,但开启Wall后,在main.c需要再次声明#include <string.h>
当然,这只是为了追求0 error 0 warning而已,即便无视这个warning其实也没啥的.
Comments
No comments yet — be the first to write one.