我有这两个文件:MinGW编译器不需要函数声明?
// first.c
int main(void) {
putint(3);
}
和
// second.c
#include <stdio.h>
void putint(int n) {
printf("%d",n);
getchar();
}
当我Win XP下运行gcc 4.6.1:
gcc first.c second.c -o program.exe
它有没有问题,写3到stdout 。它不需要putint
声明first.c。。这怎么可能?这是标准行为吗?
我已经在MSVC 2008 Express上测试过它,它只按照预期的声明运行。
// first.c
void putint(int);
int main(void) {
putint(3);
}
解决,感谢提示,这些选项有助于显示警告:
- -Wimplicit
- -std = C99(MinGW的4.6仍然默认使用gnu90)
查找“隐式函数声明” –
我做到了。我很惊讶没有任何警告。我想知道为什么? –
因为你没有告诉gcc警告你。查看gcc命令行用法。 –