VS2015 C ++调试器在读取结构时的结果很奇怪

时间:2016-03-07 18:10:06

标签: c++ visual-studio

在调试时,我在#34; test"中进行迭代时发现了以下奇怪的结果。函数来自以下示例:

enter image description here

最终结果正确显示为1.在"测试"内部时,这些值只是不正确。功能。有人可以对此有所了解吗?

它肯定与DEBUG x64版本有关,x86没有这个问题。我尝试将上面的结构对齐到4个字节,并添加了一些填充,但两者没有区别。

简约示例代码,编译于(x64):

#include "stdafx.h"

struct float3
{
    float3(float a, float b, float c) : x(a), y(b), z(c) {}
    float x, y, z;
};

float test(float3 f)
{
    float x = f.x;
    return f.x; // Breakpoint here shows the results from image
}

int main()
{
    float3 a = float3(1.0f, 2.0f, 3.0f);
    float x = test(a);
    printf("%f %f", x, a.x);
}

1 个答案:

答案 0 :(得分:1)

供将来参考,

正如Hans Passant在评论中提到的那样,通过启用工具中的“使用本机兼容模式”选项解决了这个问题 - >选项 - >调试 - >一般。