# Deferred-Shape Specifications

A deferred-shape array is an array pointer or an allocatable array.

The array specification contains a colon (:) for each dimension of the array. No bounds are specified. The bounds (and shape) of allocatable arrays and array pointers are determined when space is allocated for the array during program execution.

An array pointer is an array declared with the POINTER attribute. Its bounds and shape are determined when it is associated with a target by pointer assignment, or when the pointer is allocated by execution of an ALLOCATE statement.

In pointer assignment, the lower bound of each dimension of the array pointer is the result of the LBOUND intrinsic function applied to the corresponding dimension of the target. The upper bound of each dimension is the result of the UBOUND intrinsic function applied to the corresponding dimension of the target.

An actual argument that is a pointer can be associated with a nonpointer dummy argument. Normally, a pointer dummy argument can be associated only with a pointer actual argument. However, a pointer dummy argument with INTENT(IN) can be argument associated with a non-pointer actual argument with the TARGET attribute. During the execution of the procedure, it is pointer associated with the actual argument.

A function result can be declared to have the pointer attribute.

An allocatable array is declared with the ALLOCATABLE attribute. Its bounds and shape are determined when the array is allocated by execution of an ALLOCATE statement.

## Examples

The following are examples of deferred-shape specifications:

     REAL, ALLOCATABLE :: A(:,:)       ! Allocatable array
     REAL, POINTER :: C(:), D (:,:,:)  ! Array pointers

If a deferred-shape array is declared in a DIMENSION or TARGET statement, it must be given the ALLOCATABLE or POINTER attribute in another statement. For example:

      DIMENSION P(:, :, :)
      POINTER P

      TARGET B(:,:)
      ALLOCATABLE B

If the deferred-shape array is an array of pointers, its size, shape, and bounds are set in an ALLOCATE statement or in the pointer assignment statement when the pointer is associated with an allocated target. A pointer and its target must have the same rank.

For example:

      REAL, POINTER :: A(:,:), B(:), C(:,:)
      INTEGER, ALLOCATABLE :: I(:)
      REAL, ALLOCATABLE, TARGET :: D(:, :), E(:)
      ...
      ALLOCATE (A(2, 3), I(5), D(SIZE(I), 12), E(98) )
      C => D              ! Pointer assignment statement
      B => E(25:56)       ! Pointer assignment to a section
                          !   of a target

A pointer dummy argument with INTENT(IN) can be argument associated with a non-pointer actual argument with the TARGET attribute. It is pointer associated with the actual argument, so the following example prints “17".

    program test
       integer, target :: j = 17
       call f (j)
    contains
       subroutine f (i)
       integer, intent (in), pointer :: i
       print *,i
       end subroutine f
    end program test

Parent topic: Declarations for Arrays

## See Also

POINTER attribute
ALLOCATABLE attribute
ALLOCATE statement
Pointer assignment
LBOUND intrinsic function
UBOUND intrinsic function