associated(pointer [, target])
determines the status of the pointer pointer
or if pointer
is associated with the target target
.
Fortran 95 and later
result = associated(pointer [, target])
pointer
- pointer
shall have the pointer
attribute and it can be of any type.target
- (Optional) target
shall be a pointer or a target. It must have the same type, kind type parameter, and array rank as pointer
.The association status of neither pointer
nor target
shall be undefined.
associated(pointer)
returns a scalar value of type logical(4)
. There are several cases:
When the optional target
is not present then associated(pointer)
is true if pointer
is associated with a target; otherwise, it returns false.
If target
is present and a scalar target, the result is true if target
is not a zero-sized storage sequence and the target associated with pointer
occupies the same storage units. If pointer
is disassociated, the result is false.
If target
is present and an array target, the result is true if target
and pointer
have the same shape, are not zero-sized arrays, are arrays whose elements are not zero-sized storage sequences, and target
and pointer
occupy the same storage units in array element order.
As in case 2, the result is false, if pointer
is disassociated.
If target
is present and an scalar pointer, the result is true if target
is associated with pointer
, the target associated with target
are not zero-sized storage sequences and occupy the same storage units.
The result is false, if either target
or pointer
is disassociated.
If target
is present and an array pointer, the result is true if target associated with pointer
and the target associated with target
have the same shape, are not zero-sized arrays, are arrays whose elements are not zero-sized storage sequences, and target
and pointer
occupy the same storage units in array element order. The result is false, if either target
or pointer
is disassociated.
program test_associated
implicit none
real, target :: tgt(2) = (/1., 2./)
real, pointer :: ptr(:)
ptr => tgt
if (associated(ptr) .eqv. .false.) call abort
if (associated(ptr,tgt) .eqv. .false.) call abort
end program test_associated