c - 主要有一个参数

标签 c c89

我最近遇到一个 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/

相关文章:

c - C90 中的无符号整数加法和未定义行为

用c语言编程加农炮弹丸程序

c - 如何检查数组的元素是否是终止元素并返回新行?

c - 如何对字符串进行 base58 编码?

c: 返回目录中的所有文件名

C 编程 字符串打印

c - C89 标准中的哪一部分允许 "implicit int"规则?

在Windows上编译C99兼容的.so

c - 哪些 C99 功能被认为是有害的或不受支持的

c - 让: ** NO targets specififed and no makefile found.停止