HP Fortran Programmer's Reference (September 2007)

Data types and data objects
Pointers
Chapter 5 131
Pointers
Pointers in Fortran 90 are more strongly typed than in other languages. While it is true that
the Fortran 90 pointer holds the address of another variable (the target), it also holds
additional information about the target. For this reason, declaring a pointer requires not only
the POINTER attribute but also the type, kind parameter, and (if its target is an array) rank of
the target it can point to.
If a pointer is declared as an array with the POINTER attribute, it is an array pointer. As
explained in “Deferred-shape arrays” on page 63, the declaration for an array pointer specifies
its specifies rank but not the bounds. Following is the declaration of the array pointer ptr:
REAL(KIND=16), POINTER, DIMENSION(:,:) :: ptr
To become assignable to an array pointer, a target must be declared with the TARGET attribute
and must have the same type, kind parameter, and rank as the array pointer. Given the
previous declaration of ptr, the following are legal statements:
! declare a target with the same type, kind parameter, and
! rank as ptr
REAL(KIND=16), TARGET, DIMENSION(4,3) :: x
...
ptr => x ! assign x to ptr in a pointer assignment statement
Once the assignment statement executes, you can use either ptr or x to access the same
storage, effectively making ptr an alias of x.
You can also allocate storage to a pointer by means of the ALLOCATE statement. To deallocate
that storage after you are finished with it, use the DEALLOCATE statement. Although allocating
storage to a pointer does not involve a target object, the declaration of the pointer must still
specify its type, kind parameter, and (if you want to allocate an array) rank. The ALLOCATE
statement specifies the bounds for the dimensions. Here is an example of the ALLOCATE
statement used to allocate storage for ptr:
INTEGER :: j = 10, k = 20
...
! allocate storage for ptr
ALLOCATE (ptr(j,k))
ptr can now be referenced as though it were an array, using Fortran 90 array notation.
As an extension, HP Fortran provides the Cray-style pointer variables; for more information,
see Chapter 10. For information about aspects of pointers, refer to:
Array pointers” on page 63 for information about allocating array pointers.