Why #pragma optimize(quot;quot;, off)(为什么#pragma optimize(, off))
问题描述
我正在审查一个 C++ MFC 项目.在一些文件的开头有这样一行:
I'm reviewing a C++ MFC project. At the beginning of some of the files there is this line:
#pragma optimize("", off)
我知道这会关闭所有以下功能的优化.但这样做的动机通常是什么?
I get that this turns optimization off for all following functions. But what would the motivation typically be for doing so?
推荐答案
我见过生产代码是正确的,但过于复杂以至于让优化器产生不正确的输出.这可能是关闭优化的原因.
I've seen production code which is correct but so complicated that it confuses the optimiser into producing incorrect output. This could be the reason to turn optimisations off.
但是,我认为代码更有可能只是错误,具有未定义的行为.优化器会暴露这一点并导致不正确的运行时行为或崩溃.如果没有优化,代码恰好工作".而不是找到并消除潜在问题,而是通过禁用优化并将其留在那个位置来修复"它.
However, I'd consider it much more likely that the code is simply buggy, having Undefined Behaviour. The optimiser exposes that and leads to incorrect runtime behaviour or crashes. Without optimisations, the code happens to "work." And rather than find and remove the underlying problem, someone "fixed" it by disabling optimisations and leaving it at that.
当然,这几乎是脆弱和变通办法所能得到的.新硬件、新操作系统补丁、新编译器补丁,任何这些都可能破坏这样的修复".
Of course, this is about as fragile and workarounds can get. New hardware, new OS patch, new compiler patch, any of these can break such a "fix."
即使编译指示是出于第一个原因,它也应该被大量记录.
Even if the pragma is there for the first reason, it should be heavily documented.
这篇关于为什么#pragma optimize("", off)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么#pragma optimize("", off)
基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01