Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

TARGET Statement

Statement and Attribute: Specifies that an object can become the target of a pointer (it can be pointed to).

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

Type Declaration Statement:

type,[att-ls,] TARGET [, att-ls] :: object [(a-spec)] [[coarray-spec]] [, object[(a-spec)] [[coarray-spec]]]...

Statement:

TARGET [::] object [(a-spec)] [[coarray-spec]] [, object[(a-spec)]] [[coarray-spec]]...

type

Is a data type specifier.

att-ls

Is an optional list of attribute specifiers.

object

Is the name of the object. The object must not be declared with the PARAMETER attribute.

a-spec

(Optional) Is an array specification or a coarray specification.

coarray-spec

(Optional) Is a deferred-coshape specification. The left bracket and right bracket are required.

Description

A pointer is associated with a target by pointer assignment or by an ALLOCATE statement.

If an object does not have the TARGET attribute or has not been allocated (using an ALLOCATE statement), no part of it can be accessed by a pointer.

Example

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

TYPE(SYSTEM), TARGET :: FIRST
REAL, DIMENSION(20, 20), TARGET :: C, D

The following is an example of a TARGET statement:

TARGET :: C(50, 50), D

The following fragment is from the program POINTER2.F90 in the <install-dir>/samples subdirectory:

 ! An example of pointer assignment.
     REAL, POINTER :: arrow1 (:)
     REAL, POINTER :: arrow2 (:)
     REAL, ALLOCATABLE, TARGET :: bullseye (:)

     ALLOCATE (bullseye (7))
     bullseye = 1.
     bullseye (1:7:2) = 10.
     WRITE (*,'(/1x,a,7f8.0)') 'target ',bullseye

     arrow1 => bullseye
     WRITE (*,'(/1x,a,7f8.0)') 'pointer',arrow1
     . . .