Intel® Fortran Compiler

Developer Guide and Reference

ID 767251
Date 6/30/2025
Public
Document Table of Contents

ASSOCIATED

Inquiry Intrinsic Function (Generic): Returns the association status of its pointer argument or indicates whether the pointer is associated with the target.

result = ASSOCIATED (pointer [, target])

pointer

(Input) Must be a pointer. It can be of any data type or be a procedure pointer. The pointer association status must be defined.

target

(Input; optional) Is an entity that is either a pointer or that could be a target. If it is a pointer, its association statement must be defined.

If pointer is a procedure pointer, target must be a procedure or a procedure pointer that is allowable as a proc_target in a procedure pointer assignment.

Otherwise, target must be a non-coindexed variable that is not an array section with a vector subscript, or a reference to a function that returns a data pointer. If pointer is not unlimited polymorphic, target must be type compatible with it, and corresponding kind type parameters, if any, shall have the same values. target must have the same rank as pointer unless pointer is not assumed rank.

Results

The result is a scalar of type default logical. The setting of compiler options specifying integer size can affect this function.

If only pointer appears, the result is true if it is currently associated with a target; otherwise, the result is false.

If target is specified and is a dummy procedure that is not a procedure pointer, the result is true only if pointer is associated with the ultimate argument of the dummy procedure, and if the procedure is an internal procedure, pointer and target have the same host instance.

If target is specified and is a procedure that is not a procedure pointer or a dummy procedure, the result is true only if pointer is associated with target, and if target is a host associated procedure, they have the same host instance.

If target is specified and is a procedure pointer, the result is true only if pointer and target are associated with the same procedure, and if that procedure is an internal procedure, they have the same host instance.

If target is specified and is a scalar target, the result is true only if target is not a zero-sized storage sequence and pointer is currently associated with a target occupying the same storage units as target.

If target is specified and is an array, the result is true only if pointer is associated with a target that has the same shape, is not size zero, is not an array whose elements are zero-sized storage sequences, or occupies the same storage units as target in array element order.

If target is specified and is a scalar pointer, the result is true only if pointer and target are both associated, their targets are not zero-sized, and they occupy the same storage units.

If target is specified and is an array pointer, the result is true only if pointer and target have the same shape, are both associated, are neither zero sized arrays whose elements are not zero-sized storage sequences, and they occupy the same storage units in array element order.

Example

REAL C (:), D(:), E(5)
POINTER C, D
TARGET E
LOGICAL STATUS
C => E                       ! pointer assignment
D => E                       ! pointer assignment
STATUS = ASSOCIATED(C)       ! returns TRUE; C is associated
STATUS = ASSOCIATED(C, E)    ! returns TRUE; C is associated with E
STATUS = ASSOCIATED (C, D)   ! returns TRUE; C and D are associated
                             !   with the same target

Consider the following:

   REAL, TARGET, DIMENSION (0:50) :: TAR
   REAL, POINTER, DIMENSION (:) :: PTR
   PTR => TAR
   PRINT *, ASSOCIATED (PTR, TAR)      ! Returns the value true

The subscript range for PTR is 0:50. Consider the following pointer assignment statements:

   (1) PTR => TAR (:)
   (2) PTR => TAR (0:50)
   (3) PTR => TAR (0:49)

For statements 1 and 2, ASSOCIATED (PTR, TAR) is true because TAR has not changed (the subscript range for PTR in both cases is 1:51, following the rules for deferred-shape arrays). For statement 3, ASSOCIATED (PTR, TAR) is false because the upper bound of TAR has changed.

Consider the following:

   REAL, POINTER, DIMENSION (:) :: PTR2, PTR3
   ALLOCATE (PTR2 (0:15))
   PTR3 => PTR2
   PRINT *, ASSOCIATED (PTR2, PTR3)       ! Returns the value true
   ...
   NULLIFY (PTR2)
   NULLIFY (PTR3)
   PRINT *, ASSOCIATED (PTR2, PTR3)       ! Returns the value false