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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...