A Cray pointer is a variable whose value is the address of another entity, which is called the pointee.
f90 supports Cray pointers; Standard Fortran 90 does not.
POINTER ( pointer_name, pointee_name [array_spec] ), ...
Pointer to the corresponding pointee_name.
pointer_name contains the address of pointee_name.
Must be: a scalar variable name (but not a structure)
Cannot be: a constant, a name of a structure, an array, or a
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 nonconstant bounds), or assumed-size.
POINTER ( p, b ), ( q, c )
The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c.
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.
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.
Cray pointers do not provide convenient manipulation of linked lists because (for optimization purposes) it is assumed that no two pointers have the same value.
Cray pointers are declared as follows:
POINTER ( pointer_name, pointee_name [array_spec] )
Fortran pointers are declared as follows:
The two kinds of pointers cannot be mixed.
Whenever the pointee is referenced, f90 uses the current value of the pointer as the address of the pointee.
The Cray pointer type statement declares both the pointer and the pointee.
The Cray pointer is of type Cray pointer.
The value of a Cray pointer occupies one storage unit. Its range of values depends on the size of memory for the machine in use.
The Cray pointer can appear in a COMMON list or as a dummy argument.
The Cray pointee has no address until the value of the Cray pointer is defined.
If an array is named as a pointee, it is called a pointee array.
Its array declarator can appear in:
A separate type statement
A separate DIMENSION statement
The pointer statement itself
If the array declarator is in a subprogram, the dimensioning can refer to:
Variables in a common block, or
Variables that are dummy arguments
The size of each dimension is evaluated on entrance to the subprogram, not when the pointee is referenced.
If pointee_name is of character type, it must be a variable typed CHARACTER*(*).
If pointee_name is an array declarator, it must be explicit shape, (constant or nonconstant bounds), or assumed-size.
An array of Cray pointers is not allowed.
A Cray pointer cannot be:
Pointed to by another Cray pointer or by a Fortran pointer.
A component of a structure.
Declared to be any other data type.
A Cray pointer cannot appear in:
A PARAMETER statement or in a type declaration statement that includes the PARAMETER attribute.
A DATA statement.
A Cray pointee cannot appear in a SAVE, DATA, EQUIVALENCE, COMMON, or PARAMETER statement.
A Cray pointee cannot be a dummy argument.
A Cray pointee cannot be a function value.
A Cray pointee cannot be a structure or a structure component.
A Cray pointee cannot be of a derived type.
Cray pointees can be of type character, but their Cray pointers are different from other Cray pointers. The two kinds cannot be mixed in the same expression.
Cray pointers can be assigned values as follows:
Set to an absolute address
Example: q = 0
Assigned to or from integer variables, plus or minus expressions
Example: p = q + 100
Cray pointers are not integers. You cannot assign them to a real variable.
The LOC function (nonstandard) can be used to define a Cray pointer.
Example: p = LOC( x )
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 + 1000 ic = ib + n ...
Remarks about the above example:
word64 refers to the contents of absolute address 64
blk is an array that occupies the first 128 words of memory
a is an array of length 1000 located in blank common
b follows a and is of length n
c follows b
a, b, and c are associated with pool
word64 is the same as blk(17) because Cray pointers are byte address and the integer elements of blk are each 4 bytes long
For purposes of optimization, f90 assumes the storage of a pointee is never overlaid on the storage of another variable--it assumes that a pointee is not associated with another variable.
Such association could occur in either of two ways:
A Cray pointer has two pointees, or
Two Cray pointers are given the same value
The programmer is responsible for preventing such association.
These kinds of association are sometimes done deliberately, such as for equivalencing arrays, but then results can differ depending on whether optimization is turned on or off.
POINTER ( p, b ), ( p, c ) REAL x, b, c p = LOC( x ) b = 1.0 c = 2.0 PRINT *, b ...
Above, because b and c have the same pointer, assigning 2.0 to c gives the same value to b. Therefore b prints out as 2.0, even though it was assigned 1.0.