为什么 C++11 编译器支持仍然需要一个标志?
我了解默认情况下不应启用编程语言的实验性功能,因此我欢迎使用标志 -std=c++0x
和 -std=c++1y代码>.然而,几年前 C++11 已经成为标准.为什么编译器仍然需要
-std=c++11
来启用对其功能的支持?
I understand that experimental features of a programming language should not be enabled by default so I welcome the flags -std=c++0x
and -std=c++1y
. However C++11 is now standard since a couple of years. Why compilers still require -std=c++11
to enable the support for its features?
推荐答案
C++11 已经成为标准几年了,但是编译器不会将其默认模式切换到 C++11,直到:
C++11 has been standard for a couple of years, but a compiler isn't going to switch its default mode to C++11 until:
- 至少,该编译器及其使用的库都支持 C++11.如果编译器编写者对可靠性有任何顾虑,那么它也是稳定的.
- 最好在编译器中增加主要版本号,因为 C++11 不完全向后兼容 C++03.
- 理想情况下,按照众所周知的时间表进行,以便用户为变化做好准备.
基本上,很多人(和 makefile)依赖于编译器是一个符合 C++03 的编译器,或者至少依赖于它的不符合性是已知的.由于 C++11 引入了不符合 C++03 的新实例,因此这种变化可能会带来创伤.
Basically, lots of people (and makefiles) rely on the compiler being a conforming C++03 compiler, or at least on its non-conformance being known. Since C++11 introduces new instances of non-conformance with C++03, the change is potentially traumatic.
可以说,任何依赖 C++03 的人都应该指定一个选项来说明这一点,并且更改为默认模式对他们没有任何影响.但是,一旦您记录了编译器的默认设置,人们就会有意或无意地依赖它.
Arguably anyone relying on C++03 should have specified an option to say so, and changes to the default mode would make no difference to them. But once you've documented your compiler's default, people are going to rely that, either intentionally or otherwise.
特别是对于 gcc,4.8.2 手册页说对 C++11 的支持仍处于试验阶段".所以我认为最终你的问题的答案可能是正确实施 C++11 需要 2 年多的时间,即使是从标准草案完成的所有工作开始.
For gcc in particular, the 4.8.2 man page says that "support for C++11 is still experimental". So I think ultimately the answer to your question may be that it takes more than 2 years to properly implement C++11, even starting from all the work done with draft standards.
相关文章