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

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:

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:

IN

Specifies that the dummy argument will be used only to provide data to the procedure. The dummy argument must not be redefined (or become undefined) during execution of the procedure.

OUT

Specifies that the dummy argument will be used to pass data from the procedure back to the calling program. The dummy argument is undefined on entry, although it may have subcomponents that are initialized by default. An undefined argument must be defined before it is referenced in the procedure.

Any associated actual argument must be definable.

INOUT

Specifies that the dummy argument can both provide data to the procedure and return data to the calling program.

Any associated actual argument must be definable.

d-arg

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

Description

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 or the VALUE attribute, or both IN and the VALUE attribute.

An entity with the INTENT (OUT) attribute must not be an allocatable coarray or have a subobject that is an allocatable coarray. It must not be of, or have a subcomponent of, type EVENT_TYPE or type LOCK_TYPE from the ISO_FORTRAN_ENV module.

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

  • A DO variable

  • The variable of an assignment statement

  • The pointer-object of a pointer assignment statement

  • An object or STAT variable in an ALLOCATE or DEALLOCATE statement

  • An input item in a READ statement

  • A variable name in a NAMELIST statement if the namelist group name appears in a NML specifier in a READ statement

  • An internal file unit in a WRITE statement

  • A definable variable in an INQUIRE statement

  • An IOSTAT or SIZE specifier in an I/O statement

  • An actual argument in a reference to a procedure with an explicit interface if the associated dummy argument has intent OUT or INOUT

INTENT on a pointer dummy argument refers to the pointer association status of the pointer and has no effect on the value of the target of the pointer.

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

  • A pointer-object in a NULLIFY statement

  • A pointer-object in a pointer assignment statement

  • An object in an ALLOCATE or DEALLOCATE statement

  • An actual argument in a reference to a procedure if the associated dummy argument is a pointer with the INTENT(OUT) or INTENT(INOUT) attribute.

A pointer dummy argument with INTENT(IN) can be argument associated with a non-pointer actual argument with the TARGET attribute. During the execution of the procedure, it is pointer associated with the actual argument.

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

On entry to a routine, given an INTENT(OUT) dummy argument:

  • If it is a pointer, it should be deallocated.

  • If it is an allocatable, all of its allocatable subcomponents should be deallocated, and then it should also be deallocated.

  • If it is a non-pointer, non-allocatable, all its allocatable subcomponents should be deallocated, and then default initialization should be applied, as specified by the program.

Example

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:

SUBROUTINE AVERAGE(value,data1, cube_ave)
  TYPE DATA
  		INTEGER count
  		REAL avg
		END TYPE
		TYPE(DATA) data1
		REAL tmp
  ! 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.
  tmp = data1%count*data1%avg + value
  data1%count = data1%count + 1
  data1%avg = tmp/data1%count
  cube_ave = data1%avg**3
END SUBROUTINE