POINTER (Fortran 90)
Purpose
The POINTER attribute designates objects as pointer variables.
The term pointer refers to objects with the Fortran 90 POINTER attribute. The integer POINTER statement provides details on what was documented in previous versions of XL Fortran as the POINTER statement; these pointers are now referred to as integer pointers.
Syntax
- deferred_shape_spec
- is a colon (:), where each colon represents a dimension
Rules
object_name refers to a data object or function result. If object_name is declared elsewhere in the scoping unit with the DIMENSION attribute, the array specification must be a deferred_shape_spec_list.
object_name must not appear in an integer POINTER, NAMELIST, or EQUIVALENCE statement. If object_name is a component of a derived-type definition, any variables declared with that type cannot be specified in an EQUIVALENCE or NAMELIST statement.
Pointer variables can appear in common blocks and block data program units.
To ensure that Fortran 90 pointers
are thread-specific, do not specify either the SAVE or STATIC attribute
for the pointer. These attributes are either specified explicitly
by the user, or implicitly through the use of the -qsave compiler
option. Note, however, that if a non-static pointer is used in a pointer
assignment statement where the target is static, all references to
the pointer are, in fact, references to the static, shared target. 
An object having a component with the POINTER attribute can itself have the TARGET, INTENT, or ALLOCATABLE attibutes, although it cannot appear in a data transfer statement.
You can specify
the POINTER attribute for assumed-rank entities.
| AUTOMATIC 3 | INTENT | PUBLIC |
| ASYNCHRONOUS | OPTIONAL | SAVE |
| CONTIGUOUS 2 | PRIVATE | STATIC 3 |
| DIMENSION | PROTECTED 1 | VOLATILE |
Note:
|
||
These attributes apply only to the pointer itself, not to any associated targets, except for the DIMENSION attribute, which applies to associated targets.
Examples
INTEGER, POINTER :: PTR(:)
INTEGER, TARGET :: TARG(5)
PTR => TARG ! PTR is associated with TARG and is
! assigned an array specification of (5)
PTR(1) = 5 ! TARG(1) has value of 5
PRINT *, FUNC()
CONTAINS
REAL FUNCTION FUNC()
POINTER :: FUNC ! Function result is a pointer
.
.
.
END FUNCTION
END

FUNCTION MYFUNC(ARG) ! MYPTR is thread-specific.
INTEGER, POINTER :: MYPTR ! every thread that invokes
! 'MYFUNC' will allocate a
ALLOCATE(MYPTR) ! new piece of storage that
MYPTR = ARG ! is only accessible within
! that thread.
ANYVAR = MYPTR
END FUNCTION




