XL Fortran for AIX 8.1

Language Reference


Pointer Assignment

The pointer assignment statement causes a pointer to become associated with a target or causes the pointer's association status to become disassociated or undefined.



>>-pointer_object-- => --target--------------------------------><
 
 

target
is a variable or expression. It must have the same type, type parameters and rank as pointer_object.

pointer_object must have the POINTER attribute.

A target that is an expression must yield a value that has the POINTER attribute. A target that is a variable must have the TARGET attribute (or be a subobject of such an object) or the POINTER attribute. A target must not be an array section with a vector subscript, nor can it be a whole assumed-size array.

The size, bounds, and shape of the target of a disassociated array pointer are undefined. No part of such an array can be defined or referenced, although the array can be the argument of an intrinsic inquiry function that is inquiring about association status, argument presence, or a property of the type or type parameters.

+-------------------------------IBM Extension--------------------------------+

A pointer of type byte can only be associated with a target of type byte, INTEGER(1), or LOGICAL(1).

+----------------------------End of IBM Extension----------------------------+

Any previous association between pointer_object and a target is broken. If target is not a pointer, pointer_object becomes associated with target. If target is itself an associated pointer, pointer_object is associated with the target of target. If target is a pointer with an association status of disassociated or undefined, pointer_object acquires the same status.

Pointer assignment for a pointer structure component can also occur via execution of a derived-type intrinsic assignment statement or a defined assignment statement.

During pointer assignment of an array pointer, the lower bound of each dimension is the result of the LBOUND intrinsic function applied to the corresponding dimension of the target. For an array section or array expression that is not a whole array or a structure component, the lower bound is 1. The upper bound of each dimension is the result of the UBOUND intrinsic function applied to the corresponding dimension of the target.

Related Information:

See ALLOCATE for an alternative form of associating a pointer with a target.
See Pointers as Dummy Arguments for details on using pointers in procedure references.

Examples of Pointer Assignment

TYPE T
  INTEGER, POINTER :: COMP_PTR
ENDTYPE T
TYPE(T) T_VAR
INTEGER, POINTER :: P,Q,R
INTEGER, POINTER :: ARR(:)
BYTE, POINTER :: BYTE_PTR
LOGICAL(1), POINTER :: LOG_PTR
INTEGER, TARGET :: MYVAR
INTEGER, TARGET :: DARG(1:5)
P => MYVAR               ! P points to MYVAR
Q => P                   ! Q points to MYVAR
NULLIFY (R)              ! R is disassociated
Q => R                   ! Q is disassociated
T_VAR = T(P)             ! T_VAR%COMP_PTR points to MYVAR
ARR => DARG(1:3)
BYTE_PTR => LOG_PTR
END

+-------------------------------IBM Extension--------------------------------+

Integer Pointer Assignment

Integer pointer variables can be:

Note that the XL Fortran compiler uses 1-byte arithmetic for integer pointers in assignment statements.

Example of Integer Pointer Assignment

INTEGER INT_TEMPLATE
POINTER (P,INT_TEMPLATE)
INTEGER MY_ARRAY(10)
DATA MY_ARRAY/1,2,3,4,5,6,7,8,9,10/
INTEGER, PARAMETER :: WORDSIZE=4
 
P = LOC(MY_ARRAY)
PRINT *, INT_TEMPLATE          ! Prints '1'
P = P + 4;                     ! Add 4 to reach next element
                               !    because arithmetic is byte-based
PRINT *, INT_TEMPLATE          ! Prints '2'
 
P = LOC(MY_ARRAY)
DO I = 1,10
  PRINT *,INT_TEMPLATE
  P = P + WORDSIZE             ! Parameterized arithmetic is suggested
END DO
END

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]