c++ -/Ox 和/O2 编译器选项有什么区别?

标签 c++ visual-studio visual-c++ compiler-optimization compiler-options

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/

相关文章:

c++ - 如何在 C++ 中使用运算符重载来显示类(游戏板)

c++ - 在 Visual Studio 2017 中使用 Qt 库的 CMake 项目 : can't find Qt dll when running the exe

c# - 如何将 .Net Framework 从 3.5 版更改为 4.0 版

c++ - 在 g++ (mingw) 编译的应用程序中使用用 visual studio 编译的库

c++ - 如何在 winpcap 库中使用 pcap_sendqueue_queue()?

c - cvMemStorage的结构?

c++ - 当 friend 类具有相同名称的成员变量时会发生什么

c++ - GDB:如何将内存地址转换为STL对象

c++ - 绕行 LoadLibraryA 时 appcrash

visual-studio - 单元测试错误- “Unable to get type” “Error: Could not load type” “from assembly”