XL Fortran for AIX 8.1

Language Reference


Scope

A program unit consists of a set of nonoverlapping scoping units. A scoping unit is that portion of a program unit that has its own scope boundaries. It is one of the following:

A host scoping unit is the scoping unit that immediately surrounds another scoping unit. For example, in the following diagram, the host scoping unit of the internal function C is the scoping unit of the main program A. Host association is the method by which an internal subprogram, module subprogram, or derived-type definition accesses names from its host.




scope

Entities that have scope are:

If the scope is an executable program, the entity is called a global entity. If the scope is a scoping unit, the entity is called a local entity. If the scope is a statement or part of a statement, the entity is called a statement entity. FORTRAN 95 BeginsIf the scope is a construct, the entity is called a construct entity. FORTRAN 95 Ends

The Scope of a Name

Global Entity

+-------------------------------IBM Extension--------------------------------+

Global entities are program units, external procedures and common blocks, and CRITICAL lock_names.

+----------------------------End of IBM Extension----------------------------+

If a name identifies a global entity, it cannot be used to identify any other global entity in the same executable program.

See Conventions for XL Fortran External Names in the User's Guide for details on restrictions on names of global entities.

Local Entity

Entities of the following classes are local entities of the scoping unit in which they are defined:

  1. Named variables that are not statement entities, module procedures, named constants, derived-type definitions, construct names, generic identifiers, statement functions, internal subprograms, dummy procedures, intrinsic procedures, or namelist group names.
  2. Components of a derived-type definition (each derived-type definition has its own class).

    A component name has the same scope as the type of which it is a component. It may appear only within a component designator of a structure of that type.

    If the derived type is defined in a module and contains the PRIVATE statement, the type and its components are accessible in any of the defining module's subprograms by host association. If the accessing scoping unit accesses this type by use association, that scoping unit (and any scoping unit that accesses the entities of that scoping unit by host association) can access the derived-type definition but not its components.

  3. Argument keywords (in a separate class for each procedure with an explicit interface).

    A dummy argument name in an internal procedure, module procedure, or procedure interface block has a scope as an argument keyword of the scoping unit of its host. As an argument keyword, it may appear only in a procedure reference for the procedure of which it is a dummy argument. If the procedure or procedure interface block is accessible in another scoping unit by use association or host association, the argument keyword is accessible for procedure references for that procedure in that scoping unit.

In a scoping unit, a name that identifies a local entity of one class may be used to identify a local entity of another class. Such a name must not be used to identify another local entity of the same class, except in the case of generic names. A name that identifies a global entity in a scoping unit cannot be used to identify a local entity of Class 1 in that scoping unit, except for a common block name or the name of an external function. Components of a record structure are local entities of class 2. A separate class exists for each type.

A name declared to be a derived type using a record structure declaration may have the same name as another local entity of class 1 of that scoping unit that is not a derived type. In this case, the structure constructor for that type is not available in that scope. Similarly, a local entity of class 1 is accessible via host association or use association, even if there is another local entity of class 1 accessible in that scope, if

The structure constructor for that type will not be available in that scope. A local entity of class 1 in a scope that has the same name as a derived type accessible in that scope must be explicitly declared in a declaration statement in that scope.

If two local entities of class 1, one of which is a derived type, are accessible in a scoping unit, any PUBLIC or PRIVATE statement that specifies the name of the entities applies to both entities. If the name of the entities is specified in a VOLATILE statement, the entity or entities declared in that scope have the volatile attribute. If the two entities are public entities of a module, any rename on a USE statement that references the module and specifies the names of the entities as the use_name applies to both entities.

A common block name in a scoping unit can be the name of any local entity other than a named constant or intrinsic procedure. The name is recognized as the common block entity only when the name is delimited by slashes in a COMMON, VOLATILE, or SAVE statement. If it is not, the name identifies the local entity. An intrinsic procedure name can be the name of a common block in a scoping unit that does not reference the intrinsic procedure. In this case, the intrinsic procedure name is not accessible.

An external function name can also be the function result name. This is the only way that an external function name can also be a local entity.

If a scoping unit contains a local entity of Class 1 with the same name as an intrinsic procedure, the intrinsic procedure is not accessible in that scoping unit.

An interface block generic name can be the same as any of the procedure names in the interface block, or the same as any accessible generic name. It can be the same as any generic intrinsic procedure. See Resolution of Procedure References for details.

Statement and Construct Entities

Statement Entities

The following items are statement entities:

Except for a common block name or scalar variable name, the name of a global entity or local entity of class 1 that is accessible in the scoping unit of a statement or construct must not be the name of a statement or construct entity of that statement or construct. Within the scope of a statement or construct entity, another statement or construct entity must not have the same name.

The name of a variable that appears as a dummy argument in a statement function statement has a scope of the statement in which it appears. It has the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the statement function.

If the name of a global or local entity accessible in the scoping unit of a statement or construct is the same as the name of a statement or construct entity in that statement or construct, the name is interpreted within the scope of the statement or construct entity as that of the statement or construct entity. Elsewhere in the scoping unit, including parts of the statement or construct outside the scope of the statement or construct entity, the name is interpreted as that of the global or local entity.

If a statement or construct entity has the same name as an accessible name that denotes a variable, constant, or function, the statement or construct entity has the same type and type parameters as the variable, constant or function. Otherwise, the type of the statement or construct entity is determined through the implicit typing rules in effect. If the statement entity is the DO variable of an implied-DO in a DATA statement, the variable cannot have the same name as an accessible named constant.

+---------------------------------Fortran 95---------------------------------+

Fortran 95 Statement and Construct Entity

The following is a Fortran 95 statement and construct entity:

The only attributes held by the FORALL statement or construct entity are the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the FORALL. It is type integer.

Except for a common block name or a scalar variable name, a name that identifies a global entity or a local entity of class 1, accessible in the scoping unit of a FORALL statement or construct, must not be the same as the index_name. Within the scope of a FORALL construct, a nested FORALL statement or FORALL construct must not have the same index_name.

If the name of a global or local entity accessible in the scoping unit of a FORALL statement or construct is the same as the index_name, the name is interpreted within the scope of the FORALL statement or construct as that of the index_name. Elsewhere in the scoping unit, the name is interpreted as that of the global or local entity.

+-----------------------------End of Fortran 95------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]