views:

80

answers:

2

I have created this datastructure:

class Event
{
public:
    Event(EVENT_TYPE type, void* pSender = 0, int content1 = 0,  
        int content2 = 0, int content3 = 0, int content4 = 0);
    ~Event(void);

// ... some functions

protected:
    EVENT_TYPE itsType;
    void* itsPointerToSender;
    int itsContent_1;
    int itsContent_2;
    int itsContent_3;
    int itsContent_4;
    int numStacked;
};

whose constructor is simply

Event::Event(EVENT_TYPE type, void* pSender, int content1, int content2, int content3, int content4)
    :   itsType(type),
    itsPointerToSender(pSender),
    itsContent_1(content1),
    itsContent_2(content2),
    itsContent_3(content3),
    itsContent_4(content4),
    numStacked(0)
{
}

For some strange reason I can't understand, the VS debugger cannot and will not show me whatever is contained in itsContent_4. If I put a watch on the variable, itsContent_4 gives me a symbol "itsContent_4" not found while doing the same thing with itsContent_3 works perfectly. I'm not sure the variable even exists as far as the compiler is concerned!

Am I missing something here?

Edit: Now it seems (even stranger) that changing the order of the variables in the declaration creates an even bigger mess! I tried placing itsContent_4 before itsContent_1 and now itsContent_1 is being initialized with the value intended for itsContent_4! What is going on here? I'm suspecting something to do with naming, so I'll try renaming them all and see what happens.

Edit 2: Yes, apparently changing the variable names to itsContent_a instead of itsContent_1 and so forth works perfectly. Is there some restriction as to using numbers in a variable name?

+1  A: 

Check that you're not trying to debug a release build. In a release build the optimiser can remove unused variabled and change the order in which statements are executed. This can be confusing when debugging.

Andy Johnson
I'm on debug mode, but thanks anyway. The problem seems to occur because of the numeric suffixes of the itsContent variables...
Kristian D'Amato
Could some kind of macro substitution be occuring? Do you have the string "content" #defined?
Andy Johnson
Whenever I use #define I make use of capital letters, so that shouldn't be a problem, and anyway neither "content" nor "CONTENT" is defined. Dunno, never came across something like this before.
Kristian D'Amato
I wonder if the code you're seeing is the same as what is being fed to the compiler. Try generating a preprocessed file (right click source file in workspace and choose properties, choose Preprocessor, and select Generate Preprocessed File, and choose "Without Line Numbers". When you rebuild you'll get a <filename>.i file. Locate your class definition and constructor in it and check that the proprocessor isn't modifying them.
Andy Johnson
I've tried that now and it shows the exact same code. Having said that, I tried going back from using letter suffixes to numerical ones and now it's working well once again. I really have no idea what caused the problem. Maybe the class was not being compiled properly somehow (in fact, I had been using an Event class with only 3 itsContent variables, and the compiler was kind of using that same old class even after recompiling...)
Kristian D'Amato
+3  A: 

Sounds to me like the debugger is using the wrong .pdb file. Tools + Options, Debugging, General, ensure that "Require source files to exactly match the original version" is checked.

While debugging with a breakpoint active, use Debug + Windows + Modules and right-click your executable in the list. Click "Symbol Load Information" to find out where the debugger found the .pdb file.

Another possible mishap is that this class is defined in a separately compiled executable, like a DLL, which was compiled with incompatible settings. So that the layout of the object no longer matches. That's not that likely in this case.

Hans Passant