Viewing statics while debugging

G

Guest

How can I see the value of a static variable when debugging? Static's don't show up in the variable-window and when I type the name of a static variable in the watch-window the debugger says this the symbol is not defined

I'm in Visual C++ 6.0

Thanks
Tom
 
C

Carl Daniel [VC++ MVP]

Tom said:
How can I see the value of a static variable when debugging? Static's
don't show up in the variable-window and when I type the name of a
static variable in the watch-window the debugger says this the symbol
is not defined.

I'm in Visual C++ 6.0.

Type the fully qualified name:

struct X
{
static int i;
};

--> You need to type X::i in the watch window.

-cd
 
G

Guest

Thanks. How would I reference with the debugger a static variable that is declared and defined in a member function of a class

void theClass::theMemberFunction()

static int theVariableOfInterest = 5
. . .
// do some things including setting theVariableOfInterest to some new valu
// Somewhere down here put a breakpoin


I've tried various things, but none worked

BTW: Will this variable be shared across all instances of class 'theClass'

Thanks
To
 
C

Carl Daniel [VC++ MVP]

Tom said:
Thanks. How would I reference with the debugger a static variable
that is declared and defined in a member function of a class?

AFIAK, you can't.
void theClass::theMemberFunction()
{
static int theVariableOfInterest = 5;
. . .
// do some things including setting theVariableOfInterest to
some new value // Somewhere down here put a breakpoint
}

I've tried various things, but none worked.

You could set a breakpoint in the function, determine the address of the
local static, and then add a watch to that address, I suppose.
BTW: Will this variable be shared across all instances of class
'theClass'?

Yes.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top