C++ 有没有办法禁用特定代码行的编译器优化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4713320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is there any way to disable compiler optimisation for a specific line of code?
提问by coder1234567
is there any way to disable compiler optimisation for a specific line of code in Visual studio?
有什么方法可以禁用 Visual Studio 中特定代码行的编译器优化吗?
回答by Mitch Wheat
No.
不。
Only on a function-by-function basis using the optimize pragma:
仅在逐个函数的基础上使用优化编译指示:
#pragma optimize( "[optimization-list]", {on | off} )
The optimize pragma must appear outside a function and takes effect at the first function defined after the pragma is seen. The on and off arguments turn options specified in the optimization-list on or off.
优化编译指示必须出现在函数外部,并在看到编译指示后定义的第一个函数生效。on 和 off 参数打开或关闭优化列表中指定的选项。
usage:
用法:
#pragma optimize( "", off )
.
.
.
#pragma optimize( "", on )