C ++ 14中main()的法律定义 [英] Legal definitions of main() in C++14

查看:75
本文介绍了C ++ 14中main()的法律定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够找到的C ++ 14的最后草案是关于main() [3.6.1]:

The last draft of C++14 that I was able to find says, regarding main() [3.6.1]:

实现不应预定义主要功能.此功能不得重载.它的返回类型应该是int类型,否则它的类型是实现定义的.所有实现都应允许

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

-()返回int和

-(int,指向char的指针的指针)返回int的函数

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

和(第5段)

如果控制在没有遇到return语句的情况下到达了main的末尾,那么效果就是执行

If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

这是否意味着以下所有都是合法的C ++ 14最小程序?如果没有,为什么不呢?

Does this mean that all of the following are legal C++14 minimal programs? If any isn't, why not?

  1. auto main() -> int {}
  2. auto main() { return 0; }
  3. auto main() {}
  1. auto main() -> int {}
  2. auto main() { return 0; }
  3. auto main() {}

推荐答案

  1. 是合法的,第二个和第二个不是因为以下原因:

  1. Is legal, the second and the latter aren't because of the following reasons:

由于已接受CWG 1669,因此无法推断出主函数的返回类型,并且该标准将改写为:

The return type of the main function cannot be deduced since CWG 1669 was accepted and the standard will be reworded as:

实现不应预定义主要功能.此功能不得重载.它应该具有声明的返回类型,其类型为int,否则它的类型是实现定义的.

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.

这进入了n4140.有关此内容的更多信息: http://wg21.cmeerw.net/cwg/issue1669

This got its way into n4140. More on this: http://wg21.cmeerw.net/cwg/issue1669

与上述相同

这篇关于C ++ 14中main()的法律定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆