8.56 C_ASSOCIATED — Status of a C pointer

Synopsis:

RESULT = C_ASSOCIATED(CPTR1[, CPTR2])

Description:

C_ASSOCIATED(CPTR1[, CPTR2]) determines the status of the C pointer CPTR1 or if CPTR1 is associated with the target CPTR2.

Class:

Inquiry function

Arguments:
CPTR1Scalar of the type C_PTR or C_FUNPTR.
CPTR2(Optional) Scalar of the same type as CPTR1.
Return value:

The return value is of type LOGICAL; it is .false. if either CPTR1 is a C NULL pointer or if CPTR1 and CPTR2 point to different addresses.

Example:
subroutine association_test(a,b)
  use iso_c_binding, only: c_associated, c_loc, c_ptr
  implicit none
  real, pointer :: a
  type(c_ptr) :: b
  if(c_associated(b, c_loc(a))) &
     stop 'b and a do not point to same target'
end subroutine association_test
Standard:

Fortran 2003 and later

See also:

C_LOC — Obtain the C address of an object,
C_FUNLOC — Obtain the C address of a procedure