Content originally posted in LPCWare by xOrElse on Thu Jul 19 10:30:00 MST 2012 Hello, I have problem with global variable. Where to put global variable and how to declare it?
In main.c document I put volatile int globala=0; and it's not recognized as global. When I'm in functions I cant use it, the debugger reports it as globala isn't defined. I have no idea what to do. I'm new, and this program is so confusing.
Please help me
P.S. I used to program in C (in school), so basically I understand syntax. Main problem is where in lpcxpresso should I put global variable.
The C language does [COLOR=Red]not have a global keyword[/COLOR]. However, variables declared outside a function implicitly have a scope covering everything in the .c file or compilation unit containing its declaration. In a small program contained in a single file, such variables effectively have global scope. On the other hand, a variable that is required to have global-scope in a[COLOR=DarkOrange] multi-file project needs to be imported individually into each file using the extern keyword[/COLOR]. So don't forget to use
extern volatile int myglobal;
in multi-file project if your global is defined in another file of your project :eek: