6.3 Global variables
----------------------
Global variables are variables whose range of action is the entire
program. In C-- global variables can be used in the functions listed below
instead of declaring them, i. e., if the function uses the variable 'var'
and this variable is declared below the text of the function, the compiler
will display an error message. This is because it recognizes the variable
type only after it is declared. For this type of variable the address can
be used since it does not depend on its type. For instance:
void Proc(){
gvar = 0; /* the compiler issues an error message since it does not yet
know the type of the variable 'gvar' */
AX = #gvar; /* even though the compiler does not know the address of this
variable, the expression will be compiled */
}
int gvar;
But the case is not hopeless and our goal can be achieved using
alternate syntax for referring to the variable:
void Proc(){
DSINT[#gvar] = 0; /* the compiler successfully compile this expression
he now known type variable gvar */
}
int gvar;
the compiler will compile this expression since it now knows the type
of the variable 'gvar'
Memory for global variables is reserved in the data segment. If the
variable is initialized at declaration (i. e., if it is assigned some
value) the variable will be included in the code of the file being
compiled. If the variable is not initialized, space will be reserved for it
immediately following the final byte of the compiled program.