我最近遇到一个 C 程序,其中 main 函数只有一个参数。这在 C89 中合法吗? gcc 似乎没有任何问题。
我认为发生的是签名被忽略并且 main 被调用为 main(int,char**)
无论如何,但我不确定。
在程序中看起来是这样的:
主要(argc){
...
}
最佳答案
按照C89标准,是不合法的。来自 2.1.2.2 托管环境部分:
The function called at program startup is named `main`. The implementation declares no prototype for this function. It can be defined with no parameters: int main(void) { /*...*/ } or with two parameters (referred to here as argc and argv , though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /*...*/ }
C99 标准在5.1.2.2.1 程序启动部分中有同样的规定。
关于c - 主要有一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11262609/