Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Fortran 90 Programmer's Reference > Chapter 10 HP Fortran 90 statements

POINTER (statement and attribute)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

Specifies variables with the POINTER attribute.

Syntax

The 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:

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.

Description

A 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.

Examples

In 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 statements

ALLOCATE, DEALLOCATE, NULLIFY and TARGET

Related concepts

For related information, see the following:

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.