Pet*_*ett 3 c gcc compilation c99 compiler-warnings
在 C 中,函数声明可以是原型声明或非原型声明。例如,考虑以下最小程序:
int foo (); /* non-prototype declaration */
int bar (void); /* prototype declaration */
int main (int argc, char **argv)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尽管在 C99 中非原型声明已经过时,但我无法让 GCC 抱怨它们。例如,使用 GCC 编译上述程序并启用所有错误就会成功:
$ gcc -std=c99 -pedantic -Werror -Wall test.c
$
Run Code Online (Sandbox Code Playgroud)
有没有办法说服 GCC 对不是原型的函数声明发出警告?
(问题的灵感来自Keith Thompson的回答。)