5.15 POINTER Attribute and Statement

The POINTER attribute specifies that an object is a pointer (a dynamic variable). A pointer does not contain data, but points to a scalar or array variable where data is stored. A pointer has no initial storage set aside for it; memory storage is created for the pointer as a program runs.

The POINTER attribute can be specified in a type declaration statement or a POINTER statement, and takes one of the following forms:

Type Declaration Statement:

type, [att-ls,] POINTER [, att-ls] :: ptr [(d-spec)] [, ptr [(d-spec)]]...

Statement:

POINTER [::] ptr [(d-spec)] [, ptr [(d-spec)]]...

type
Is a data type specifier.

att-ls
Is an optional list of attribute specifiers.

ptr
Is the name of the pointer. The pointer cannot be declared with the INTENT or PARAMETER attributes.

d-spec
Is a deferred-shape specification (: [,:]...). Each colon represents a dimension of the array.

Rules and Behavior

No storage space is created for a pointer until it is allocated with an ALLOCATE statement or until it is assigned to a allocated target. A pointer must not be referenced or defined until memory is associated with it.

Each pointer has an association status, which tells whether the pointer is currently associated with a target object. When a pointer is initially declared, its status is undefined. You can use the ASSOCIATED intrinsic function to find the association status of a pointer.

If the pointer is an array, and it is given the DIMENSION attribute elsewhere in the program, it must be declared as a deferred-shape array.

A pointer cannot be specified in a DATA, EQUIVALENCE, or NAMELIST statement.

Examples

The following example shows type declaration statements specifying the POINTER attribute:

TYPE(SYSTEM), POINTER :: CURRENT, LAST
REAL, DIMENSION(:,:), POINTER :: I, J, REVERSE

The following is an example of the POINTER statement:

TYPE(SYSTEM) :: TODAYS
POINTER :: TODAYS, A(:,:)

For More Information:


Previous Page Next Page Table of Contents