gpt4 book ai didi

c - 为什么 Visual Studio 不知道这个结构的正确定义?

转载 作者:太空宇宙 更新时间:2023-11-04 07:42:56 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题,几乎像是 Visual Studio 2008 的问题。我有一个 C 结构定义如下:

static struct frame {
short typupdt;
char callarg[1+CallSiz];
char *unitarg;
XTime unitage;
XTime orgtime;
XTime newtime;
char oldstat[1+StatSiz];
char newstat[1+StatSiz];
char incdisp[1+DispSiz];
char orgdisp[1+DispSiz];
char clearcod[1+ClearSiz];
char orgclear[1+ClearSiz];
char observd[1+ObsSiz];
char orgobs[1+ObsSiz];
char raddesc[1+Desc1Siz];
char incnum[INVIDLEN];
char agency[1+AgencySiz];
int wlins;
int wcols;
int skipsrch;
struct frame *next;
} *Frame= NULL;

应该(并且似乎)创建一个新的 struct称为 frame和一个指向该 struct 实例的全局指针(指向此文件)称为 Frame .这一切似乎在代码本身中运行良好。但是,当我调试此代码并在某处设置断点然后检查 Frame 时在监 window 口中,它报告的信息是完全错误的。这就像它正在查看正确的内存片段,但它对定义的理解是不正确的,即它所说的结构具有的字段甚至都不接近。

起初我认为有某种奇怪的命名空间问题或其他问题所以我更改了两个 frame 的名称和 Frame ,但问题依然存在。有人知道发生了什么事吗?就像我说的,代码似乎可以工作,但调试几乎是不可能的。

编辑:我用真实定义更新了定义,这是我在监 window 口中看到的屏幕截图:

alt text http://img156.imageshack.us/img156/6943/watchlist.jpg

这对任何人都有意义吗?我仍然非常难过。

最佳答案

Microsoft 描述了您的情况:FIX: Wrong Type Definition Appears in Visual Studio .NET Debugger

WORKAROUND: Microsoft strongly recommends that you use unique type definitions. By using unique type definitions, you can avoid any confusion about the true value of a data structure. However, if you cannot use unique type definitions, you can also avoid the problem by using namespaces, as in the following sample code:

namespace MyNamespace {
struct IDENTICALSTRUCT {
...;
};

using namespace MyNamespace;

The debugger can then resolve the type definitions correctly.

关于c - 为什么 Visual Studio 不知道这个结构的正确定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1574875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com