将 DWORD 显式初始化为 1,但调试器显示超出范围的值 [英] Explicitly initialize DWORD to 1, but debugger shows wildly out of range value

查看:19
本文介绍了将 DWORD 显式初始化为 1,但调试器显示超出范围的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个问题有点失望 - 在调试模式下这个问题根本没有出现,但在发布模式下,我感觉几乎无能为力.

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,但调试器显示超出范围的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆