INTENT

Statement and Attribute: Specifies the intended use of one or more dummy arguments.

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

Syntax

Type Declaration Statement:

type, [att-ls,] INTENT (intent-spec) [, att-ls] :: d-arg [, d-arg] ...

Statement:

INTENT (intent-spec) [::] d-arg [, d-arg] ...

type
Is a data type specifier.

att-ls
Is an optional list of attribute specifiers.

intent-spec
Is one of the following specifiers:


d-arg
Is the name of a dummy argument. It cannot be a dummy procedure or dummy pointer.

Rules and Behavior

The INTENT statement can only appear in the specification part of a subprogram or interface body.

If no INTENT attribute is specified for a dummy argument, its use is subject to the limitations of the associated actual argument.

If a function specifies a defined operator, the dummy arguments must have intent IN.

If a subroutine specifies defined assignment, the first argument must have intent OUT or INOUT, and the second argument must have intent IN.

A dummy argument with intent IN (or a subobject of such a dummy argument) must not appear as any of the following:

If an actual argument is an array section with a vector subscript, it cannot be associated with a dummy array that is defined or redefined (has intent OUT or INOUT).

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS DLL LIB

See Also: Argument Association, Type Declarations, Compatible attributes

Examples

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

SUBROUTINE TEST(I, J)
  INTEGER, INTENT(IN) :: I
  INTEGER, INTENT(OUT), DIMENSION(I) :: J

The following are examples of the INTENT statement:

SUBROUTINE TEST(A, B, X)
   INTENT(INOUT) :: A, B
   ...

SUBROUTINE CHANGE(FROM, TO)
   USE EMPLOYEE_MODULE
   TYPE(EMPLOYEE) FROM, TO
   INTENT(IN) FROM
   INTENT(OUT) TO
   ...

The following shows another example:

!Calculate value into a running average and return the average cubed.

TYPE DATA
  INTEGER count
  REAL average
END TYPE
. . .
SUBROUTINE AVERAGE(value,data1,cube_ave)
  TYPE(DATA) data1
  REAL dummy
  ! value cannot be changed, while cube_ave must be defined
  ! before it can be used. Data1 is defined when the procedure is
  ! invoked, and becomes redefined in the subroutine.
  INTENT(IN)::value; INTENT(OUT)::cube_ave
  INTENT(INOUT)::data1

  ! count number of times AVERAGE has been called on the data set
  ! being passed.
  dummy = count*average + value
  data1%count = data1%count + 1
  data1%average = dummy/data1%count
  cube_ave = data1%average**3
END SUBROUTINE