Hi,
I've a multifile program in C and I need to use global variables. I've one header file that is called "global.h" where my global variable is defined. In the other files, there's an include directive to "global.h".
At the moment, I'm using my variable in the C files without declaration in the other files using the word extern and the program works. My question is: is that correct because I've read that global variables should be defined once and declared in evry file using those variables using the keyword extern?
global.h
int myVar;
main.c
include "global.h"
...
int someFct()
{
myVar = something;
}
otherfile.c
include "global.h"
...
int otherFct()
{
if (myVar == myCondition)
{
}
}
Thank you!