Jump to content

I can't see a global variable

Recommended Posts

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


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.

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.

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...