Search code examples
cvisual-studio-2008struct

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. I have a C struct definition as follows:

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. 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. It's like it's looking at the correct piece of memory, but its understanding of the definition is incorrect, i.e. 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. 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

That Make a lick of sense to anybody? I'm still super stumped.


Solution

  • There's something about your situation described by 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.