問題描述
我對這個問題有點失望 - 在調試模式下這個問題根本沒有出現,但在發布模式下,我感覺幾乎無能為力.
I'm a bit flabberghasted with this issue - in debug mode this issue doesn't come up at all, but in release mode it feels like there's almost nothing I can do to fix it.
這是 VS2013 內部發生的截圖:
Here's a screenshot of what's going on inside VS2013:
我將nResult
初始化為1L,內部值顯示為3422785012.在Debug模式下,這個值確實是1L.
I initialize nResult
to 1L, and the internal value is shown as 3422785012. In Debug mode, this value is indeed 1L.
關于為什么顯示的值甚至不接近我為 nResult
設置的初始值的任何想法?我試過使用編譯器設置 - 在調試模式下,此代碼運行良好.
Any ideas as to why the displayed value isn't even close to the initial value I set for nResult
? I've tried playing with compiler settings - in Debug mode this code runs fine.
推薦答案
您的代碼很可能優化
.這意味著編譯器以一種您的源代碼與編譯器生成的內容不匹配的方式移動和刪除了代碼.
Your code is more than likely optimized
. This means that the compiler has moved and eliminated code in a way that your source code does not match what the compiler has produced.
要么調試未優化的代碼,要么在充分了解源代碼可能與正在執行的實際指令不匹配的情況下調試優化代碼.
Either debug unoptimized code, or debug optimized code with the full knowledge that the source may not match the actual instructions being performed.
如果您想調試發布版本但在調試器中看到正確的值,請轉到 Visual Studio 中項目的屬性,轉到 C/C++ 部分,然后禁用優化.重建.
If you want to debug a release build but see the correct values in the debugger, go to the Properties of your project in Visual Studio, go to the C/C++ section, and disable the optimizations. Rebuild.
這篇關于將 DWORD 顯式初始化為 1,但調試器顯示超出范圍的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!