Scope

Program entities have the following kinds of scope (as shown in the table below):

Scope of Program Entities

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

See Also