Association exists if the same data can be identified with different names in the same scoping unit, or with the same name or different names in different scoping units of the same executable program.
Host association allows an internal subprogram, module subprogram, or derived-type definition to access named entities that exist in its host. Accessed entities have the same attributes and are known by the same name (if available) as they are in the host. The entities are named objects, derived-type definitions, namelist groups, interface blocks and procedures.
A name that is specified with the EXTERNAL attribute is a global name. Any entity in the host scoping unit that has this name as its nongeneric name is inaccessible by that name and by host association.
The following list of entities are local within a scoping unit when declared or initialized in that scoping unit:
Entities that are local to a subprogram are not accessible in the host scoping unit.
A local entity must not be referenced or defined before the DATA statement when:
If a derived-type name of a host is inaccessible, structures of that type or subobjects of such structures are still accessible.
If a subprogram gains access to a pointer (or integer pointer) by host association, the pointer association that exists at the time the subprogram is invoked remains current within the subprogram. This pointer association can be changed within the subprogram. The pointer association remains current when the procedure finishes executing, except when this causes the pointer to become undefined, in which case the association status of the host-associated pointer becomes undefined.
An interface body does not access named entities through host association, although it can access entities by use association.
The host scoping unit of an internal or module subprogram can contain the same use-associated entities.
SUBROUTINE MYSUB TYPE DATES ! Define DATES INTEGER START INTEGER END END TYPE DATES CONTAINS INTEGER FUNCTION MYFUNC(PNAME) TYPE PLANTS TYPE (DATES) LIFESPAN ! Host association of DATES CHARACTER(10) SPECIES INTEGER PHOTOPER END TYPE PLANTS END FUNCTION MYFUNC END SUBROUTINE MYSUB
Use association occurs when a scoping unit accesses the entities of a module with the USE statement. Use-associated entities can be renamed for use in the local scoping unit. The association is in effect for the duration of the executable program. See USE for details.
MODULE M CONTAINS SUBROUTINE PRINTCHAR(X) CHARACTER(20) X PRINT *, X END SUBROUTINE END MODULE PROGRAM MAIN USE M ! Accesses public entities of module M CHARACTER(20) :: NAME='George' CALL PRINTCHAR(NAME) ! Calls PRINTCHAR from module M END
A target that is associated with a pointer can be referenced by a reference to the pointer. This is called pointer association.
A pointer always has an association status:
P => T
NULLIFY (Q); P => Q
POINTER P(:), Q(:) ALLOCATE (P(3)) Q => P DEALLOCATE (Q) ! Deallocate target of P through Q. ! P is now undefined. END
The definition status of a pointer is that of its target. If a pointer is associated with a definable target, the definition status of the pointer can be defined or undefined according to the rules for a variable.
If the association status of a pointer is disassociated or undefined, the pointer must not be referenced or deallocated. Whatever its association status, a pointer can always be nullified, allocated or pointer-assigned. When it is allocated, its definition status is undefined. When it is pointer-assigned, its association and definition status are determined by its target. So, if a pointer becomes associated with a target that is defined, the pointer becomes defined.
An integer pointer that is associated with a data object can be used to reference the data object. This is called integer pointer association.
Integer pointer association can only occur in the following situations:
POINTER (P,A) P=LOC(B) ! A and B become associated
POINTER (P,A), (P,B) ! A and B are associated
POINTER (P,A), (Q,B) P=LOC(C) Q=LOC(C) ! A, B, and C become associated
POINTER (P,A) . . CALL SUB (P,B) . . SUBROUTINE SUB (P,X) POINTER (P,Y) P=LOC(X) ! Main program variables A ! and B become associated.
+----------------------------End of IBM Extension----------------------------+