main() 的链接是实现定义的是什么意思?

What does it mean that linkage of main() is implementation defined?

C++ 标准第 3.6.1/3 节说

The linkage of main is implementation-defined

这是什么意思?为什么要定义实现?在 C 中也一样吗?

因为对函数 main 的引用是被禁止的(如果您引用整个规则会有所帮助),main 的链接对用户代码绝对没有影响:

The function main shall not be used within a program. The linkage of main is implementation-defined. A program that defines main as deleted or that declares main to be inline, static, or constexpr is ill-formed. The name main is not otherwise reserved.

链接控制名称可用的范围,main() 函数的名称根本无法在您的代码的任何地方使用,因此尝试用链接标记它没有意义.

C++ 的目的是提供一种可移植的编程抽象。许多事情都由标准指定,以便无论您是否将 C++ 转换为程序集、JavaScript、奶酪、煎锅或超级模型,都不会产生歧义。

main 的链接不是其中之一,因为它有点抽象泄漏:它是(理论上)与执行 machine/cheese/frying 的片段交互的函数平移并处理跨越该边界的数据。数据输入,数据输出。

关于 main 函数的大量细节不应该是标准强制的,因为 main 的全部目的是与标准无法控制的事物进行交互。

也就是说,there are still significant restrictions emplaced upon main,在大多数实现中,它甚至不用作入口点 — 编译器的 C++ 运行时中的一些内部函数通常会充当入口点,执行静态初始化和其他一些调用 main 之前的事情,因为,这是唯一明智的方法。