Intel® Fortran Compiler 18.0 Developer Guide and Reference
Program entities have the following kinds of scope (as shown in the table below):
Global
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.
Scoping unit (Local scope)
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 the table below).
A scoping unit is one of the following:
A derived-type definition
A procedure interface body (excluding any derived-type definitions and interface bodies contained within it)
A program unit or subprogram (excluding any derived-type definitions, interface bodies, and subprograms contained within it)
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 Use and Host Association.
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 the table below.
Statement
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.
Entity |
Scope |
|
---|---|---|
Program units |
Global |
|
Common blocks1 |
Global |
|
External procedures |
Global |
|
Intrinsic procedures |
Global2 |
|
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 list3 of a DATA or FORALL statement, or an array constructor |
Statement |
|
Intrinsic operators |
Global |
|
Defined operators |
Local |
|
Statement labels |
Local |
|
External I/O unit numbers |
Global |
|
Intrinsic assignment |
Global4 |
|
Defined assignment |
Local |
|
1 Names of common blocks can also be used to identify local entities. 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 Defining Generic Assignment). |
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