Pointer association
A target that is associated with a pointer can be referenced by a reference to the pointer. This is called pointer association.
- 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
- The ALLOCATE statement successfully
allocates the pointer, which has not been subsequently disassociated
or undefined.
- 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)
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
execution 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
- The pointer is successfully deallocated.
DEALLOCATE (P)
- The pointer is pointer-assigned to a disassociated pointer.
NULLIFY (Q); P => Q
- The pointer is nullified by a NULLIFY statement
or by the -qinit=f90ptr option. See -qinit in the XL Fortran Compiler Reference.
- Undefined
-
- Initially (unless the -qinit=f90ptr option is specified)
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).
- 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.
The 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
The pointer is an unsaved, local pointer of a BLOCK construct, and the execution of the BLOCK construct is complete.
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.