Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 6/24/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Scope

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, unless access is blocked by an IMPORT ONLY or IMPORT NONE statement. 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 or an OpenMP* reduction identifier 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 generic name can be the same as the name of a derived type.

    An OpenMP* reduction identifier can be the same as any local entity name.

    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 common block, or a local or construct variable accessible in the same scoping unit or construct; in this case, the name is interpreted within the statement as that of the statement entity.

  • Construct

    Construct entities are accessible during the execution of the construct in which they are declared. Entities declared in the specification part of a BLOCK construct, associate names in ASSOCIATE, SELECT RANK, and SELECT TYPE constructs, and index variables in FORALL statements or constructs, or DO CONCURRENT constructs are construct entities. An index name of an inner FORALL statement or construct, or of a DO CONCURRENT construct cannot be the same as that of an index variable of an outer (containing) FORALL or DO CONCURRENT construct.

    An associate name of a SELECT TYPE construct has a different scope for each block of the construct; the declared type, dynamic type, type parameters, rank or bounds may differ from block to block. An associate name for a SELECT RANK construct has a different scope for each block of the construct since the rank of the associate name is different in each block. An associate name for an ASSOCIATE construct has the scope of the ASSOCIATE construct.

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 or construct

Class I

Components of derived types

Local

Class II

Named constants

Local or construct

Class I

Named constructs

Local or construct

Class I

Namelist group names

Local

Class I

OpenMP* reduction identifier

Local

Class I

Generic identifiers

Local or construct

Class I

Argument keywords in procedures

Local

Class III

Variables

Local or construct

Class I

Variables that are dummy arguments in statement functions

Statement

DO variables in an implied-DO list3 of a DATA statement, or an array constructor

Statement

DO index variables of a FORALL statement or construct, or a DO CONCURRENT construct

Construct

Associate names

Construct

Intrinsic operators

Global

Defined operators

Local or construct

Statement labels

Local

External I/O unit numbers

Global

Intrinsic assignment

Global4

Defined assignment

Local or construct

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
           BLOCK                 !             Scoping unit 7
           ...                   !             Scoping unit 7
           END BLOCK             !             Scoping unit 7
         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