Jump to content
danieldlo09

I can't see a global variable

Recommended Posts

In CCSvs5 in the debugger i can't see the global variable that i declared, altougth it work perfectly when i run the code. This variable should appear, doesn't it? how do i do to see it?

 

post-34760-0-72633200-1384383009_thumb.jpg

Share this post


Link to post
Share on other sites

Not sure if that's what confuses the debugger, but you don't need the

extern int unsigned count
declaration in main.

 

You only need extern for variables and functions that are declared in another module, i.e. can't be resolved by the compiler. See

http://stackoverflow.com/questions/496448/how-to-correctly-use-the-extern-keyword-in-c

Share this post


Link to post
Share on other sites

You can right click and Add Watch Expression

 

Yeah, it worked!!!. I hadn't tried it because i was focused in the "variables" tab and there was not enable. But in the Expressions tab it was enable.

Share this post


Link to post
Share on other sites

Your line

extern unsigned int count;

in the main() function instructs the compiler/linker that you have a unsigned int count defined in another compilation unit, so another c file.

C scoping rules say that your outer scope (global) is always visible in your inner scope (main), unless you have an identically named variable in your inner scope. Hence leaving the extern.... line out entirely will expose the global count variable to your main() function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×