gpt4 book ai didi

c - C中main()的返回类型

转载 作者:行者123 更新时间:2023-12-04 11:04:29 25 4
gpt4 key购买 nike

阅读 C11 标准,在谈到 main() 时,我读到:

5.1.2.2.1 "...[main] shall be defined with a return type of int".
5.1.2.2.3 "...If the return type is not compatible with int,..."

后者建议我可以定义 main() 来返回一个非整数值。
如果 main “应该”返回 int 怎么可能?

而且,“该实现没有为此函数声明原型(prototype)”是否允许使用非整数返回类型?
为什么紧接着说:“[main] 应定义为返回类型为 int”?

最佳答案

我印象中的句子

or in some other implementation-defined manner.

这里会引起混淆。 implementation-defined 是由编译器提供商定义和记录 的 C 标准术语。这并不意味着程序员可以自由地为 main 选择任意原型(prototype)。这意味着他可以使用不同的原型(prototype),如果他的编译器文档预见到的话。

我所知道的唯一其他特定于平台的返回类型是 void,它在一些较旧的平台上是允许的。对于 main 的参数,我知道一些平台允许第三个参数传递一个指向环境的指针。

关于c - C中main()的返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21663570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com