Data pointer assignment

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

Read syntax diagramSkip visual syntax diagram
>>-data_pointer_object--+-----------------------------+-- => --target-><
                        |                    (1)      |                 
                        +-(bounds_spec_list)----------+                 
                        |                         (2) |                 
                        '-(bounds_remapping_list)-----'                 

Notes:
  1. Fortran 2003
  2. Fortran 2003
data_pointer_object
must have the POINTER attribute.
target
is a variable or expression. If it is a variable, it must have the TARGET attribute (or be a subobject of such an object) or the POINTER attribute. If it is an expression, it must yield a value that has the POINTER attribute.

If target is not unlimited polymorphic, data_pointer_object must be type compatible with it and the corresponding kind type parameters must be equal. If target is unlimited polymorphic, data_pointer_object must be unlimited polymorphic, of sequence derived type, or of a type with the BIND attribute.

Fortran 2003 begins
bounds_spec
Read syntax diagramSkip visual syntax diagram
>>-lower_bound --:---------------------------------------------><

lower_bound
is a scalar integer expression.
bounds_remapping
Read syntax diagramSkip visual syntax diagram
>>-lower_bound : upper_bound-----------------------------------><

lower_bound
is a scalar integer expression.
upper_bound
is a scalar integer expression.
Fortran 2003 ends

A target must not be an array section with a vector subscript, or 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 beginsA pointer of type byte can only be associated with a target of type byte, INTEGER(1), or LOGICAL(1). IBM extension ends

Fortran 2008 beginsIf a data_pointer_object is an array with the CONTIGUOUS attribute, the target must be contiguous.Fortran 2008 ends

Fortran 2003 begins

If target is a disassociated pointer, all nondeferred type parameters of the declared type of data_pointer_object that correspond to nondeferred type parameters of target shall have the same values as the corresponding type parameters of target. Otherwise, all nondeferred type parameters of the declared type of data_pointer_object must have the same values as the corresponding type parameters of target.

If data_pointer_object has nondeferred type parameters that correspond to deferred type parameters of target, target must not be a pointer with undefined association status.

If the data_pointer_object is not polymorphic and the target is polymorphic with dynamic type that differs from its declared type, the assignment target is the ancestor component of target that has the type of data_pointer_object. Otherwise, the assignment target is target.

If data_pointer_object is polymorphic, it assumes the dynamic type of target. If data_pointer_object is of sequence derived type or a type with the BIND attribute, the dynamic type of target must be that type.

If you specify bounds_spec_list, the number of bounds in the list must be equal to the rank of data_pointer_object.

If you specify either a bounds_spec_list or a bounds_remapping_list, you must not use a SUBSCRIPTORDER directive on the pointer

If you specify a bounds_remapping_list:
  • Fortran 2008 beginsThe target must be simply contiguous or of rank one.Fortran 2008 ends
  • The target must not be a diassociated or undefined pointer, and the size of the target must not be less than the size of the data_pointer_object.
  • The number of bounds_remappings in the list must be equal to the rank of data_pointer_object.
  • The lower bound of each dimension of the data_pointer_object becomes equal to the lower_bound you specify in the corresponding bounds_remapping.
  • The upper bound of each dimension of the data_pointer_object becomes equal to the upper_bound you specify in the corresponding bounds_remapping.
  • The extent of each dimension of the data_pointer_object is equal to the upper bound of that dimension, minus the lower bound of that dimension, plus 1.
  • The elements of the target of data-pointer-object, in array element order, are the first SIZE (data-pointer-object) elements of the target, after any SUBSCRIPTORDER directives affect the target.
If you specify a bounds_spec_list:
  • The number of bounds_spec shall equal the rank of data_pointer_object.
  • If you specify a bounds_spec_list, then the lower_bound of each dimension of the data_pointer_object becomes equal to the lower_bound in the corresponding bounds_spec.
  • The extent of each dimension of the data_pointer_object is equal to the extent of the corresponding dimension of the target.
  • The upper bound of each dimension of the data_pointer_object is equal to the lower bound of that dimension, plus the extent of that dimension, minus 1.
Fortran 2003 ends

If neither bounds_remapping_list nor bounds_spec_list are specified:

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.

Any previous association between a data_pointer_object and a target is broken. If target is not a pointer, data_pointer_object becomes associated with target. If target is itself an associated pointer, data_pointer_object is associated with the target of target. If target is a pointer with an association status of disassociated or undefined, data_pointer_object acquires the same status. If target of a pointer assignment is an allocatable object, it must be allocated.

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

Related information



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us