Sun Studio 12 Update 1: Fortran User's Guide

4.3 Cray Pointers

A Cray pointer is a variable whose value is the address of another entity, called the pointee.

f95 supports Cray pointers; Standard Fortran 95 does not.

4.3.1 Syntax

The Cray POINTER statement has the following format:

POINTER  ( pointer_name, pointee_name [array_spec] ), …

Where pointer_name, pointee_name, and array_spec are as follows:


Pointer to the corresponding pointee_name.

pointer_name contains the address of pointee_name.Must be a scalar variable name (but not a derived type).Cannot be: a constant, a name of a structure, an array, or a function.


Pointee of the corresponding pointer_name

Must be: a variable name, array declarator, or array name


If array_spec is present, it must be explicit shape, (constant or non-constant bounds), or assumed-size.

For example, we can declare Cray pointers to two pointees:

    POINTER ( p, b ),  ( q, c )

The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c.

We can also declare a Cray pointer to an array:

     POINTER ( ix, x(n, 0:m) )

The above example declares Cray pointer ix and its pointee x; and declares x to be an array of dimensions n by m+1.

4.3.2 Purpose of Cray Pointers

You can use pointers to access user-managed storage by dynamically associating variables to particular locations in a block of storage.

Cray pointers allow accessing absolute memory locations.

4.3.3 Declaring Cray Pointers and Fortran 95 Pointers

Cray pointers are declared as follows:

POINTER ( pointer_name, pointee_name [array_spec] )

Fortran 95 pointers are declared as follows:

POINTER object_name

The two kinds of pointers cannot be mixed.

4.3.4 Features of Cray Pointers

4.3.5 Restrictions on Cray Pointers

4.3.6 Restrictions on Cray Pointees

4.3.7 Usage of Cray Pointers

Cray pointers can be assigned values as follows:

Example: Use Cray pointers as described above.

    SUBROUTINE  sub ( n )
    COMMON pool(100000)
    INTEGER blk(128), word64
    REAL a(1000), b(n), c(100000-n-1000)
    POINTER ( pblk, blk ), (ia, a ), ( ib, b ), &
            ( ic, c ), ( address, word64 )
    DATA address / 64 /
    pblk = 0
    ia = LOC( pool )
    ib = ia + 4000
    ic = ib + n

Remarks about the above example: