Microsoft 的 C++ 编译器(cl.exe
,包含在 Visual Studio 中)提供 several optimization switches .它们中的大多数之间的区别似乎不言自明,但我不清楚 /O2
(优化代码以获得最大速度)和 /Ox
(选择“完全优化”)。
我已尝试阅读 documentation对于 /Ox
选项,似乎确认此开关还可以优化最大速度,而不是大小:
The
/Ox
compiler option produces code that favors execution speed over smaller size.
但特别是“备注”部分下的以下声明引起了我的注意:
In general, specify
/O2
(Maximize Speed) instead of/Ox
.
所以我的问题是,为什么人们通常更喜欢 /O2
而不是 /Ox
? 后一种选项是否启用了已知的特定优化?导致不可预见的错误或其他意外行为?仅仅是获得的优化量不值得额外的编译时间吗?或者这只是一个完全没有意义的“建议”,因为 /O2
是 VS 中的 default 选项?
最佳答案
我找到了 here :
Ox and O2 are almost identical. They differ only in the fact that O2 also throws GF and Gy. There is almost no reason to avoid throwing these two switches.
关于c++ -/Ox 和/O2 编译器选项有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5063334/