gpt4 book ai didi

c++ - 隐式返回 0 如何与 main 的返回类型推导联系起来?

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:57 24 4
gpt4 key购买 nike

<分区>

N3936 [basic.start.main]

2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a declared return type of type int, but otherwise its type is implementation-defined. An implementation shall allow both

— a function of () returning int and

— a function of (int, pointer to pointer to char) returning int

5 A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

DR 1669在措辞中添加了单词声明,暗示如果main将被宣布 auto ,尾随返回类型是必需的。然而,DR 1003引入的措辞就像上面的引述一样,“一个实现应该允许两个函数......返回int......”当涉及到main的声明时,这个措辞不那么严格。应该看起来像。

因此,给定 auto 的规则, 是隐含的 return 0;足以让

auto main() { }

合法吗?

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