Program entities have the following kinds of scope (as shown in Table 16-1):
Entities that are accessible throughout an executable program. The name of a global entity must be unique. It cannot be used to identify any other global entity in the same executable program.
Entities that are declared within a scoping unit. These entities are local to that scoping unit. The names of local entities are divided into classes (see Table 16-1).
A scoping unit is one of the following:
A scoping unit that immediately surrounds another scoping unit is called the host scoping unit. Named entities within the host scoping unit are accessible to the nested scoping unit by host association. (For information about host association, see Section 188.8.131.52.)
Once an entity is declared in a scoping unit, its name can be used throughout that scoping unit. An entity declared in another scoping unit is a different entity even if it has the same name and properties.
Within a scoping unit, a local entity name that is not generic must be unique within its class. However, the name of a local entity in one class can be used to identify a local entity of another class.
Within a scoping unit, a generic name can be the same as any one of the procedure names in the interface block.
A component name has the same scope as the derived type of which it is a component. It can appear only within a component designator of a structure of that type.
For information on interactions between local and global names, see Table 16-1.
Entities that are accessible only within a statement or part of a statement; such entities cannot be referenced in subsequent statements.
The name of a statement entity can also be the name of a global or local entity in the same scoping unit; in this case, the name is interpreted within the statement as that of the statement entity.
Table 16-1 Scope of Program Entities
|Common blocks 1||Global|
|Intrinsic procedures||Global 2|
|Module procedures||Local||Class I|
|Internal procedures||Local||Class I|
|Dummy procedures||Local||Class I|
|Statement functions||Local||Class I|
|Derived types||Local||Class I|
|Components of derived types||Local||Class II|
|Named constants||Local||Class I|
|Named constructs||Local||Class I|
|Namelist group names||Local||Class I|
|Generic identifiers||Local||Class I|
|Argument keywords in procedures||Local||Class III|
|Variables that can be referenced throughout a subprogram||Local||Class I|
|Variables that are dummy arguments in statement functions||Statement|
|DO variables in an implied-do list 3 of a DATA or FORALL statement, or an array constructor||Statement|
|External I/O unit numbers||Global|
|Intrinsic assignment||Global 4|
1 Names of common blocks can also be used to identify local
2 If an intrinsic procedure is not used in a scoping unit, its name can be used as a local entity within that scoping unit. For example, if intrinsic function COS is not used in a program unit, COS can be used as a local variable there.
3 The DO variable in an implied-do list of an I/O list has local scope.
4 The scope of the assignment symbol (=) is global, but it can identify additional operations (see Section 8.9.5).
Scoping units can contain other scoping units. For example, the following shows six scoping units:
MODULE MOD_1 ! Scoping unit 1 ... ! Scoping unit 1 CONTAINS ! Scoping unit 1 FUNCTION FIRST ! Scoping unit 2 TYPE NAME ! Scoping unit 3 ... ! Scoping unit 3 END TYPE NAME ! Scoping unit 3 ... ! Scoping unit 2 CONTAINS ! Scoping unit 2 SUBROUTINE SUB_B ! Scoping unit 4 TYPE PROCESS ! Scoping unit 5 ... ! Scoping unit 5 END TYPE PROCESS ! Scoping unit 5 INTERFACE ! Scoping unit 5 SUBROUTINE SUB_A ! Scoping unit 6 ... ! Scoping unit 6 END SUBROUTINE SUB_A ! Scoping unit 6 END INTERFACE ! Scoping unit 5 END SUBROUTINE SUB_B ! Scoping unit 4 END FUNCTION FIRST ! Scoping unit 2 END MODULE ! Scoping unit 1
For More Information: