c++ 吗?标准禁止 void main() 原型?
在 C++ 标准 1998 和 2003 版的 3.6.1.2 节中,
实现不应预定义主函数。该函数不得超载。它将 具有 int 类型的返回类型,但除此之外,其类型是实现定义的。
我不是以英语为母语的人。我不知道“但是否则”是什么意思。是否是禁止其他返回类型,或者给予C++编译器编写者权利?
那么答案是什么呢?
In section 3.6.1.2 of both C++ Standard 1998 and 2003 editions,
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.
I am not a native English speaker.I do not sure what does"but otherwise" means.Whether it is to prohibit the other return type,or to give the right to C++ compiler writer?
So what's the answer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您引用的英语确实禁止声明
main
返回void
。它允许传入参数的变化,但不允许返回类型的变化。The english you quote does prohibit declaring
main
to returnvoid
. It is allowing variation in the arguments that come in, but not in the return type.啊啊!是的,确实如此。标准允许的唯一返回类型是 int。引用第 3.6.1 节:
这意味着它可能看起来像这样:
等等等等。
Aaargh! Yes it does. The only return type allowed by the standard is int. To quote from section 3.6.1:
meaning it could look like this:
etc. etc.
该类型不仅仅包含返回类型。因此,返回类型必须是 int,但是您可以自由考虑剩余的参数,即您可以在 和 之间进行
选择
The type contains more than just the return type. Hence, the return type must be int, but you are free considering the remaining argument, i.e. you may e.g., select between
and
标准规定返回类型必须为 int,但类型的其余部分取决于实现。例如,您可以制作一个符合标准(但不是很有用)的 C++ 编译器。
来自维基百科:
The standard is saying that the return type must be
int
, but that the rest of the type is up to the implementation. For example, you could make a standard-compliant (but not terribly useful) C++ compiler that used.From Wikipedia:
就参数而言,它允许
int main()
int main(int argc , char * argv[])
int main(int argc , char * argv[] , char * envr[])
但作为为了保持一致性,每个标准返回类型应为int。
As far as parameters are concern ,it allows
int main()
int main(int argc , char * argv[])
int main(int argc , char * argv[] , char * envr[])
But as per standard return type should be int for consistency purpose.
其目的是说,除返回类型之外的
main
函数类型的各个方面都是实现定义的。这意味着该标准的这一子句允许此声明:但不允许此声明:
其返回类型必须为
int
,但实现允许具有不同的参数类型。The intent is to say that aspects of the type of the
main
function other than the return type are implementation defined. That means this declaration is allowed by this clause of the standard:but not this one:
Its return type must be
int
, but the implementation is allowed to have different argument types.