 |
» |
|
|
 |
Specifies variables
with the POINTER attribute. SyntaxThe syntax of a type declaration statement with the POINTER attribute is: type, attrib-list :: dummy-argument-name-list |
- type
is a valid type specification (INTEGER, REAL, LOGICAL, CHARACTER, TYPE ( name), etc.). - attrib-list
is a comma-separated list of attributes including POINTER and optionally those attributes compatible with
it, namely: Table 10-44 Title not available (POINTER (statement and attribute)) DIMENSION | PRIVATE | SAVE | OPTIONAL | PUBLIC | |
- dummy-argument-name-list
is a comma-separated list of dummy-argument-names.
The syntax of the POINTER statement is: POINTER [::] object-name [(deferred-shape-spec-list)] |
[,object-name [(deferred-shape-spec-list)]]... |
- object-name
is a data object or function result. - deferred-shape-spec-list
is a comma-separated list of colons.
DescriptionA POINTER attribute or statement specifies that the named
variables may be pointers to some target object. Pointers provide
a capability for creating dynamic objects, such as dynamic-sized
arrays and linked lists. An object with a pointer attribute initially
has no space reserved for its target. A pointer is assigned space
for its target when an ALLOCATE statement is executed or when it is assigned to
point to a target using a pointer assignment statement. ExamplesIn the first example, two array pointers are declared and
used. ! Extents are not specified; they are determined during execution REAL, POINTER :: weight (:,:,:) REAL, POINTER :: w_reg (:,:,:) READ *, i, j, k ALLOCATE (weight (i, j, k)) ! create weight ! w_reg is an alias for an array section w_reg => weight (3:i-2, 3:j-2, 3:k-2) avg_w = sum (w_reg) / ((i-4) * (j-4) * (k-4)) DEALLOCATE (weight) ! weight no longer needed |
The next example illustrates the use of pointers in a list-processing
application. TYPE link REAL value TYPE (link), POINTER :: next END TYPE link TYPE(link), POINTER :: list, save_list NULLIFY (list) ! Initialize list DO READ (*, *, IOSTAT = no_more) value IF (no_more /= 0) EXIT save_list => list ALLOCATE (list) ! Add link to head of list list % value = value list % next => save_list END DO ! Linked list removed when no longer needed DO IF (.NOT.ASSOCIATED (list) ) EXIT save_list => list % next DEALLOCATE (list) list => save_list END DO |
Related statementsALLOCATE, DEALLOCATE, NULLIFY and TARGET Related conceptsFor related information, see the following:
|