编辑:澄清,因为有人试图编辑这篇文章,我的意思是vim显示警告,gcc没有。
我有一个程序使用以下命令行正确编译而没有警告:
gcc -o stetest -pedantic -Wall strerrortest.c
然而,vim警告我,我在下面的MWE中指出的行上有一个隐含的strerror声明。这是我应该担心的事情,还是它正确编译的事实?我应该写一个原型来让警告消失吗?
警告是
implicit declaration of function 'strerror' [-Wimplicit-function-declaration]
format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Wformat=]
来源:
// strerrortest.c
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
int
main(int argc, char ** argv)
{
fprintf(stderr,"%s\n",strerror(1));
// Vim complains about an implicit declaration of strerror here.
return 0;
}
系统是Ubuntu 15.04。
答案 0 :(得分:-2)
问题是你调用gcc编译器的方式。
vim的命令应该是:
!gcc -c strerrortest.c -o strerrortest.o -I/usr/include
然而,可以消除其中的几个部分 通过vim.ini文件中的适当条目
答案 1 :(得分:-4)
只需替换您的代码
fprintf(stderr,"%d\n",strerror(1));