extern data and static diffenece since static is used for keeping the value after existing function, extern use the value in other module. are they the same?
sorry, I was a bit off, read my post as to "static" and "global". :( Of course, if something is "extern" it must be global, so thus "extern" makes sense. I do agree that a variable can be global without being used extern, but why the heck would anyone do that? Erik
"I do agree that a variable can be global without being used extern, but why the heck would anyone do that?" In 'C', everything defined at file scope is automatically "Public" - whether or not any other module actually references it. You use 'static' with file-scope objects if you want to prevent them from being "Public"
I do agree that a variable can be global without being used extern, but why the heck would anyone do that? So that you can watch that variable from outside the scope of the file in which it is declared. If the variable isn't global, some debuggers can't watch it if it is out of scope (if you're not debugging some code in that source file). Of course, not all debuggers work this way. Jon
"If the variable isn't global, some debuggers can't watch it if it is out of scope" In uVision, to watch a function's static local variable from outside the function, you have to give the fully-qualified name like "\\module\function\fred" instead of just "fred" I presume it would be similar for file-scope objects declared 'static'?
"In uVision, to watch a function's static local variable from outside the function, you have to give the fully-qualified name like '\\module\function\fred' instead of just 'fred'" Having just been trying to watch a 'static' local, I now remember that it's worse than that: Actually, you always have to give the fully-qualified name - whether or not the variable is currently in-scope. This is a pain, as it means that the pop-up display of the current value doesn't work, the variable doesn't appear in the 'locals' window, and you can't add it to a Watch window by right clicking. :-( PS The syntax is actually '\module\function\fred' - only a single backslash to start