TARGET

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:

Syntax

Type Declaration Statement:

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

Statement:

TARGET [::] object [(a-spec)] [, object [(a-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.

Rules and Behavior

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.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: ALLOCATE, ASSOCIATED, POINTER, Pointer Assignments, Pointer Association, Type Declarations, Compatible attributes

Examples

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 \DF\SAMPLES\TUTORIAL 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
     . . .