main()的链接定义为实现是什么意思? [英] What does it mean that linkage of main() is implementation defined?

查看:47
本文介绍了main()的链接定义为实现是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++标准第3.6.1/3节指出

main的链接是实现定义的

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

解决方案

C ++的目的是在编程上提供可移植的抽象.该标准指定了许多内容,以便无论您将C ++转换为程序集,JavaScript,奶酪,煎锅还是超模型,都可以做到明确.

main 的链接不是其中之一,因为它有点抽象泄漏:(理论上)它是与执行机器/奶酪/零件交互的功能煎锅并处理跨越该边界的数据.数据输入,数据输出.

关于 main 函数的实质性细节不应由标准规定,因为 main 的全部目的是与标准无法控制的事物进行交互./strong>

话虽这么说, main 上仍然存在重大限制,在大多数情况下的实现,甚至不用作入口点—在调用 main 之前,编译器C ++运行时中的某些内部函数通常将用作入口点,执行静态初始化和其他一些操作,因为,那是唯一明智的方法./p>

C++ standard section 3.6.1/3 says that

The linkage of main is implementation-defined

What does it mean? Why it is implementation defined? Is it same in C also?

解决方案

The purpose of C++ is to provide a portable abstraction over programming. Many things are specified by the standard so as to be unambiguous regardless of whether you translate your C++ to assembly, JavaScript, cheese, frying pans or supermodels.

The linkage of main is not one of those things, because it is a bit of an abstraction leak: it is (theoretically) the function that interacts with the pieces of the executing machine/cheese/frying pan and handles data crossing that boundary. Data in, data out.

Substantial details about the main function should not be standard-mandated because the entire purpose of main is to interface with things that the standard cannot control.

That being said, there are still significant restrictions emplaced upon main, and in most implementations it's not even used as the entrypoint — some internal function in your compiler's C++ runtime will usually act as the the entrypoint, performing static initialisation and a few other things before invoking main, because, well, that's about the only sane way to do it.

这篇关于main()的链接定义为实现是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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