我刚刚注意到GCC的行为,这对我来说似乎很陌生(未与其他编译器一起检查过)。调用带有太多参数的函数时的GCC行为
如果我编译此代码:
#include <stdio.h>
void foo(int i)
{
printf("Hello %d\n",i);
}
int main(){
foo(1, 2);
return 0;
}
我会得到一个编译错误:
test.c:9:5: error: too many arguments to function ‘foo’
但如果我编译此代码:
#include <stdio.h>
void foo()
{
printf("Hello\n");
}
int main(){
foo(1, 2);
return 0;
}
我没有得到任何错误或警告。
有人能解释我为什么吗?
我用gcc 4.6.3试用了一下手臂,无 - EABI-GCC 4.8.3
编辑:我编译所有的警告:gcc -Wall test.c
加上'-pedantic'获得更多的警告 – mch
@mch谢谢你的提示,在这种情况下,它不会警告任何 – Quentin
您需要-Wstrict的原型让海湾合作委员会警告它。 –