Visual Studio debugger displays address of struct instead of struct itself?

I recently came across some very strange behavior in Visual Studio 2008, and have yet to be able to explain it. I did try to re-create the following behavior in a very small application which using the same datatypes, and unfortunately was not able to recreate it. Whatever it is, it seems to be an artifact of something else in my larger application.

The issue seems to be related to passing a structure by value into a function. Please, let's not start a debate on passing structures by reference/value, there's enough of that out there already. Passing by value is permitted and is what is used here.

The issue in a nutshell is that the debugger is showing incorrect values for the members of a structure that happens to be the first input of the function. The following screenshot shows the watch window displaying the values of a different representations of the structure. Note that "InternalId" is the input to the function, and Visual Studio is displaying the value 1520176(0x00173230 in hex) for its first member 'local_id'. However, the printf statement below prints out the decimal value '1028' (this is the value I would expect local_id to contain).

在这里输入图像描述

Note in the screenshot that I've created a pointer to the input structure "pInternalId", and then created another copy of the struct "InternalId2" by de-referencing the pointer. The debugger is displaying those variables properly.

Note the value of "pInternalId", it is 0x00173230, which of course is the address of InternalId. This happens to be what the debugger is showing for the contents of InternalId.local_id! WAT?

Has anyone encountered something similar? My program seems to be operating correctly, but this certainly sent me on a wild-goose chase for a few hours.

I'll see if I can get a newer version of Visual Studio and attempt to re-create.

链接地址: http://www.djcxy.com/p/95368.html

上一篇: 在Visual Studio 2008中进行本地化

下一篇: Visual Studio调试器显示结构的地址而不是结构本身?