Pointer association

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:
Associated
  • The ALLOCATE statement successfully allocates the pointer, which has not been subsequently disassociated or undefined.
    ALLOCATE (P(3))
  • The pointer is pointer-assigned to a target that is associated or has the TARGET attribute and, if allocatable, is allocated.
    P => T
Disassociated
  • The pointer is nullified by a NULLIFY statement or by the -qinit=f90ptr option. See -qinit in the XL Fortran Compiler Reference.
    NULLIFY (P)
  • Fortran 2003 begins The pointer is an ultimate component of an object with default initialization specified for the component and:
    • a procedure is invoked with this object as an actual argument corresponding to a nonpointer, nonallocatable dummy argument with INTENT(OUT),
    • a procedure with the object as an unsaved nonpointer, nonallocatable local object that is not accessed by use or host association is invoked,
    • this object is allocated, or
    • Fortran 2008 beginsexecution enters a BLOCK construct, and the object is an unsaved, nonpointer, nonallocatable, local variable of the BLOCK construct,
      TYPE DT
         INTEGER, POINTER :: POINT => NULL()
      END TYPE
      
      BLOCK
        TYPE(DT) DT1  ! DT1%POINT becomes disassociated here
      END BLOCK
      Fortran 2008 ends
    Fortran 2003 ends
  • The pointer is successfully deallocated.
    DEALLOCATE (P)
  • The pointer is pointer-assigned to a disassociated pointer.
    NULLIFY (Q); P => Q
Undefined
  • Initially (unless the -qinit=f90ptr option is specified)
  • Fortran 2003 begins The pointer is an ultimate component of an object, default initialization is not specified for the component, and a procedure is invoked with this object as an actual argument corresponding to a dummy argument with INTENT(OUT), or a procedure is invoked with the pointer as an actual argument corresponding to a pointer dummy argument with INTENT(OUT). Fortran 2003 ends
  • If it is pointer-assigned to a pointer whose association status is undefined.
  • If its target was deallocated other than through the pointer.
    POINTER P(:), Q(:)
    ALLOCATE (P(3))
    Q => P
    DEALLOCATE (Q)   ! Deallocate target of P through Q.
                     ! P is now undefined.
    END
  • If the execution of a RETURN or END statement causes the pointer's target to become undefined.
  • After the execution of a RETURN or END statement in a procedure where the pointer was declared or accessed, except for objects described in item 4 under Events causing undefinition.
  • Fortran 2008 beginsThe target of the pointer becomes undefined when execution exits a BLOCK construct.
    INTEGER, POINTER :: POINT
    BLOCK
      INTEGER, TARGET :: TARG = 2
      POINT => TARG
    END BLOCK  ! point becomes undefined here 
    Fortran 2008 ends
  • Fortran 2008 beginsThe pointer is an unsaved, local pointer of a BLOCK construct, and the execution of the BLOCK construct is complete.Fortran 2008 ends

Definition status and association status

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.