Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

c++ - Explicitly initialize DWORD to 1, but debugger shows wildly out of range value

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.

Here's a screenshot of what's going on inside VS2013:

enter image description here

I initialize nResult to 1L, and the internal value is shown as 3422785012. In Debug mode, this value is indeed 1L.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...