you
define the variable (allocate memory for it) in one file (and you can initialise it here)
-
int data=100; // define the variable
-
you then
declare the variable in all other files that use it by prefixing it with extern (saying it is defined elsewhere)
-
extern int data; // declare the variable
-
you can only initailse the variable when you define it
don't initialise the varaiable when you declare it, e.g.
-
extern int data=10; // declare the variable
-
otherwise the compiler with give warnings or error messages, e.g. from MPLAB
-
ADNS6090.c:60: warning: 'data' initialized and declared 'extern'