The POINTER statement discussed here is different from the one
discussed in Section 5.15. It
establishes pairs of variables and pointers, in which each pointer
contains the address of its paired variable.
This POINTER statement takes the following form:
- POINTER (pointer, pointee) [, (pointer,
pointee)] . . .
Is a variable whose value is used as the address of the
Is a variable; it can be an array name or array specification.
Rules and Behavior
The following are pointer rules and behavior:
- Two pointers can have the same value, so pointer aliasing
- When used directly, a pointer is treated like an integer
variable. On Alpha and ia64 processors, a pointer
occupies two numeric storage units, so it is a 64-bit quantity
(INTEGER(8)). On ia32 processors, a pointer
occupies one numeric storage unit, so it is a 32-bit quantity
- A pointer cannot be a pointee.
- A pointer cannot appear in an ASSIGN statement and cannot
have the following attributes:
A pointer can appear in a DATA statement with integer literals
- Integers can be converted to pointers, so you can point to
absolute memory locations.
- A pointer variable cannot be declared to have any other
- A pointer cannot be a function return value.
- You can give values to pointers by doing the following:
- Retrieve addresses by using the LOC intrinsic function
(or the %LOC built-in function)
- Allocate storage for an object by using the MALLOC
intrinsic function (or by using
Tru64 UNIX or Linux systems, or LIB$GET_VM on OpenVMS systems)
Using %LOC: Using MALLOC: Using LIB$GET_VM:
INTEGER I(10) INTEGER I(10) INTEGER I(10)
INTEGER I1(10) /10*10/ POINTER (P,I) INTEGER LIB$GET_VM,STATUS
POINTER (P,I) P = MALLOC(40) POINTER (P,I)
P = %LOC(I1) I(2) = I(2) + 1 STATUS = LIB$GET_VM(P,40)
I(2) = I(2) + 1 IF (.NOT. STATUS) CALL EXIT(STATUS)
I(2) = I(2) + 1
- The value in a pointer is used as the pointee's base
The following are pointee rules and behavior:
- A pointee is not allocated any storage. References to a
pointee look to the current contents of its associated pointer to
find the pointee's base address.
- A pointee cannot be data-initialized or have a record
structure that contains data-initialized fields.
- A pointee can appear in only one POINTER statement.
- A pointee array can have fixed, adjustable, or assumed
- A pointee cannot appear in a COMMON, DATA, EQUIVALENCE, or
NAMELIST statement, and it cannot have the following attributes:
- A pointee cannot be:
- A dummy argument
- A function return value
- A record field or an array element
- An automatic object
- The name of a generic interface block
- If a pointee is of derived type, it must be of sequence
Previous Page Next Page Table of Contents