c++ - main() 函数是否使用了 odr?

标签 c++ language-lawyer program-entry-point one-definition-rule

main()函数odr-used ?例如在这样的简单程序中:

int main()
{
}

最佳答案

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

[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 没有出现在可能被求值的表达式中,因此它没有被 odr 使用。此外,我们必须考虑以下几点:

[basic.start.main]

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

这是否适用于简单地调用 main 或任何用途,可能值得商榷,但它肯定会限制您在任何程序中使用 odr-use main 的选项。

在分析 odr-use 时,值得牢记的是 程序 odr-uses 实体(或不使用它们)。外部力量(例如使用 main 作为入口点的实现)不受该辩论的影响。

关于c++ - main() 函数是否使用了 odr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54166888/

相关文章:

c++ - C++中的顶级是什么?

c++ - ARM 交叉编译 : undefined reference to '__fdelt_chk@GLIBC_2.15'

c++ - << 运算符在 C++ 中重载用于日志目的

c++ - 包含其他 header 的单个 header

ios - 为什么 UIApplicationMain 函数被命名为类命名风格

c++ - 从主 C++ 解析参数

java - Sonarqube 未涵盖主要代码

c++ - 在作为引用传递的参数中创建对象

c++ - `pair::operator=(pair&&)` 错误与 `auto&` 推断 move 操作 - libstdc++ 回归?

c++ - 基类是依赖类型时是否存在缺陷