3.3.1.4 How Can I Use A Variable Defined In Another Source File?
Provided the variable defined in the other source file is not
static
(see 10.2.2 Static Variables) or auto
(see 10.3 Auto Variable Allocation and Access), adding a declaration
for that variable into the current file will allow you to access it. A declaration consists
of the keyword extern
in addition to the type and the name of the
variable, as specified in its definition, for example,
extern int systemStatus;
This is part of the C language. Your favorite C textbook will give you more information.
The position of the declaration in the current file determines the scope of the variable. That is, if you place the declaration inside a function, it will limit the scope of the variable to that function. If you place it outside of a function, it allows access to the variable in all functions for the remainder of the current file.
Often, declarations are placed in header files and then they are
#include
d into the C source code (see 22.2 Preprocessor Directives).