Is the main() function odr-used?

只谈情不闲聊 提交于 2020-01-15 11:55:06

问题


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

int main()
{
}

回答1:


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

[basic.def.odr]

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 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 The function main shall not be used within a program.

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.

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.



来源:https://stackoverflow.com/questions/54166888/is-the-main-function-odr-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!