[英]Why does Visual Studio not know the correct definition of this struct?
I've got a weird issue that almost seems like a Visual Studio 2008 issue. 我遇到了一个奇怪的问题,几乎像是Visual Studio 2008问题。 I have a C struct definition as follows:
我有一个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;
Which should (and seems to) create a new struct
called frame
and a global pointer (to this file) to an instance of that struct
called Frame
. 哪个应该(并且似乎)创建一个称为
frame
的新struct
以及一个指向该struct
实例Frame
的全局指针(指向此文件)。 That all seems to work fine in the code itself. 一切似乎在代码本身中都可以正常工作。 However, when I am debugging this code and set a break point somewhere and then examine
Frame
in the watch window, the information it reports is completely wrong. 但是,当我调试此代码并在某个位置设置断点,然后在监视窗口中检查
Frame
时,它报告的信息是完全错误的。 It's like it's looking at the correct piece of memory, but its understanding of the definition is incorrect, ie the fields it says the struct has are not even close. 就像正在查看正确的内存一样,但是它对定义的理解是不正确的,也就是说,它说该结构所具有的字段甚至不紧密。
At first I thought there was sort of weird namespacing issue or something so I changed the names of both frame
and Frame
, but the issue still existed. 最初我以为是一个奇怪的命名空间问题,所以我同时更改了
frame
和Frame
的名称,但是问题仍然存在。 Anybody have any idea what is going on? 有人知道发生了什么吗? Like I said, the code seems to work, but debugging is pretty much impossible.
就像我说的那样,代码似乎可以工作,但是调试几乎是不可能的。
Edit: I updated the definition with the real definition, and here's a screenshot of what I see in the watch window: 编辑:我用实际定义更新了定义,这是我在监视窗口中看到的屏幕截图:
alt text http://img156.imageshack.us/img156/6943/watchlist.jpg 替代文字http://img156.imageshack.us/img156/6943/watchlist.jpg
That Make a lick of sense to anybody? 那对任何人都有意义吗? I'm still super stumped.
我还是很困惑。
There's something about your situation described by Microsoft: Microsoft对您的情况有一些描述: http://support.microsoft.com/kb/822551
http://support.microsoft.com/kb/822551
WORKAROUND : Microsoft strongly recommends that you use unique type definitions.
解决方法 :Microsoft强烈建议您使用唯一的类型定义。
The problem is that this 问题是
struct foo { /*...*/ } * bar;
defines bar
to be a foo*
, not a foo
. 将
bar
定义为foo*
,而不是foo
。 Try 尝试
struct foo { /*...*/ } bar;
instead. 代替。
Are you running a Debug build? 您正在运行调试版本吗? Debugging a release build will often seem to work, but the debugger will report garbage values for variables.
调试发行版似乎通常可以工作,但是调试器将报告变量的垃圾值。
If that's not it, then I'd try to verify if it is a compiler/syntax issue by splitting up the definition so you define the struct as a typedef and then define the pointer in a separate statement. 如果不是,那么我将尝试通过拆分定义来验证它是否是编译器/语法问题,以便将结构定义为typedef,然后在单独的语句中定义指针。 (This would arguably make the code more readable/maintainable anyway - if you don't trust the code above then rewriting it in a way that you do trust is advisable)
(可以说,这无论如何都会使代码更具可读性/可维护性-如果您不信任上面的代码,那么建议以您信任的方式重写它)
Try declaring the struct frame
and defining a variable of that type in different statements. 尝试声明
struct frame
并在不同的语句中定义该类型的变量。
struct frame {
/* .. Various other fields, etc */
struct frame *next;
};
static struct frame *Frame = NULL;
Maybe the static
messes up Visual Studio. 也许
static
搞砸了Visual Studio。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.