main()函数是否已使用? [英] Is the main() function odr-used?

查看:86
本文介绍了main()函数是否已使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main()函数是使用过 ?例如,在这样的简单程序中:

Is the main() function odr-used? E.g in the simple program like this:

int main()
{
}

推荐答案

不,不是.不在您的简单程序中.

No, it is not. Not in your simple program.

[basic.def.odr]

3 一个函数的名称显示为潜在评估 如果表达式是唯一的查找结果或 一组重载函数([basic.lookup], [over.match],[over.over]),除非它是纯虚函数并且 其名称未明确限定,或者该表达式形成一个 指向成员([expr.unary.op])的指针.

3 A function whose name appears as a potentially-evaluated expression is odr-used if it is the unique lookup result or the selected member of a set of overloaded functions ([basic.lookup], [over.match], [over.over]), unless it is a pure virtual function and either its name is not explicitly qualified or the expression forms a pointer to member ([expr.unary.op]).

main不会出现在可能评估的表达式中,因此不会被过度使用.此外,我们必须考虑以下几点:

main does not appear in a potentially evaluated expression, as such it is not odr-used. Furthermore, we must consider the following:

[basic.start.main]

3 不得使用main函数在程序中.

3 The function main shall not be used within a program.

这是否适用于简单的调用 main或任何用途,还是有争议的,但这无疑将您的选择限制为在任何程序中使用odr-use main.

Whether or not that applies to simply calling main, or any use, is maybe debatable, but it certainly limits your options to odr-use main in any program.

在分析odr-use时值得牢记的是,odr-uses实体(或不使用它们)是程序.外部力量(例如使用main作为切入点的实施方式)无需争论.

It's worth keeping in mind when analyzing odr-use that it is the program that odr-uses entities (or not uses them). Outside forces (such as the implementation using main as the entry point) are not subject to that debate.

这篇关于main()函数是否已使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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