5. COMMON STATEMENT
This statement is used to define and introduce global
variables in FORTRAN. Two types of COMMON statements
are available: Blank and labeled COMMON statement.
Blank COMMON statement
When COMMON statement is used in a program, a separate
area is set up in the computer memory. Space in this
area is allocated only to the variables appearing
with the COMMON statement.
For example: COMMON ALPHA, BETA, GAMA.
The variables ALPHA, BETA, and GAMA are assigned
the memory locations #1, #2, and #3 respectively in
the global area. If another program unit contains
the statement COMMON A, B, C, then these three variables
are also assigned the first three memory locations
in the common area. The following table shows the
relationship:
Variable
|
Blank Common
location |
Variable
|
ALPHA |
1 |
A |
BETA |
2 |
B |
GAMA
|
3 |
C |
Therefore, any reference to ALPHA is equivalent to
the reference to A, and so on.
Labeled COMMON statement
The named COMMON allows establishment of more than
one common regions each of which is uniquely named.
The general form of a labeled COMMON statement is:
COMMON / NAME1/ list1,list2n /NAME2/ list3, list4
Variable list1and list2 are common variable and have
been grouped together and given a name NAME1. Variable
list3and list4 are common variable and have been grouped
together and given a name NAME2.
|