Intel® Fortran Compiler 18.0 Developer Guide and Reference

Host Association

Host association allows the entities in a host scoping unit to be accessible to an internal subprogram, a module subprogram, or submodule program. This association remains in effect throughout the execution of the program.

The following also have access to entities from its host:

The accessed entities are known by the same name and have the same attributes as in the host, except that a local entity can have the ASYNCHRONOUS attribute even if the host entity does not, and a noncoarray local entity can have the VOLATILE attribute even if the host entity does not. The accessed entities can be named data objects, derived types, abstract interfaces, procedures, generic identifiers, and namelist groups.

Entities that are local to a procedure are not accessible to their hosts.

The following are considered local identifiers within a scoping unit so they are not accessible to their hosts:

A name that appears in an ASYNCHRONOUS or VOLATILE statement is not necessarily the name of a local variable. In an internal or module procedure, if a variable that is accessible via host association is specified in an ASYNCHRONOUS or VOLATILE statement, that host variable is given the ASYNCHRONOUS or VOLATILE attribute in the local scope.

If an intrinsic procedure is accessed by means of host association, it must be established to be intrinsic in the host scoping unit by one of the following methods:

If a procedure gains access to a pointer by host association, the association of the pointer with a target that is current at the time the procedure is invoked remains current within the procedure. This pointer association can be changed within the procedure. After execution of the procedure, the pointer association remains current, unless the execution caused the target to become undefined. If this occurs, the host associated pointer becomes undefined.

NOTE

Implicit declarations can cause problems for host association. It is recommended that you use IMPLICIT NONE in both the host and the contained procedure, and that you explicitly declare all entities.

When all entities are explicitly declared, local declarations override host declarations, and host declarations that are not overridden are available in the contained procedure.

Examples

The following example shows how a host and an internal procedure can use host-associated entities:

 program INTERNAL
 ! shows use of internal subroutine and CONTAINS statement
    real a,b,c
    call find
    print *, c
 contains
    subroutine find
      read *, a,b
      c = sqrt(a**2 + b**2)
    end subroutine find
 end

In this case, the variables a, b, and c are available to the internal subroutine find through host association. They do not have to be passed as arguments to the internal procedure. In fact, if they are, they become local variables to the subroutine and hide the variables declared in the host program.

Conversely, the host program knows the value of c, when it returns from the internal subroutine that has defined c.

See Also