![]() |
![]() |
![]() |
![]() |
![]() |
|
In summary, when more than one file uses a global variable, the global variable must be defined in one file and declared in all the others. The declaration may be by way of an included header file:
The mode variable is defined as a global variable in this file
|
| Same global mode variable is declared in this file
| |
v v
mode.c mode.h
*------------------* *------------------*
| int mode; | | extern int mode; |
| | | | --* Inclusion makes
*------------------* *------------------* | mode variable
*------------------------*------------* available in
main.c v trades.c v main.c and in
*------------------* *------------------* trades.c
| #include mode.h | | #include mode.h |
| | | |
*------------------* *------------------*