FORTRAN Reference Manual

Statements
FORTRAN Reference Manual528615-001
7-21
COMMON Statement
If you declare a common block name more than once in the same program unit,
the compiler treats each such common block as a continuation of the first
declaration. The following statements:
COMMON /tax/ jan,feb,march,//tax rate
COMMON /tax/ april,may,//surcharge
are equivalent to the single statement:
COMMON /tax/ jan,feb,march,april,may,//tax rate,surcharge
Storage of items in common blocks
Each program unit references data items in its common blocks according to the
layout it declares. Thus, if program unit A includes the statement
COMMON /customer/ debit, credit, balance
and program unit B includes the statement
COMMON /customer/ balance, credit, debit
the data items in the CUSTOMER common block have the following form:
Program A and program B both declare a common block named CUSTOMER that
contains three 32-bit REAL variables. The diagram shows that:
°
Program As variable DEBIT and program B’s variable BALANCE share the
same 32 bits.
°
Program As variable CREDIT and program B’s variable CREDIT share the
same 32 bits.
°
Program As variable BALANCE and program B’s variable DEBIT share the
same 32 bits.
If program unit A modifies the value of DEBIT, it also modifies the value of
BALANCE in program unit B. If this is not the effect sought, be careful to maintain
consistent naming of common storage items.
Equivalencing entities in common blocks
Entities declared in COMMON statements cannot be equivalenced to each other,
but a variable, array, or array element that is not in a COMMON block can be
equivalenced to a data item that is in a common block. Although an
EQUIVALENCE statement must not attempt to expand a common block by adding
entities to storage ahead of the first entity in the block, it can extend a common
DEBIT
CREDIT
BALANCE
BALANCE
DEBIT
CREDIT
PROGRAM A:
PROGRAM B:
32 bits 32 bits 32 bits
VST071.vsd