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

ID 767251
Date 7/13/2023
Public

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

Document Table of Contents

Define Generic Operators

An interface block can be used to define a generic operator. The only procedures allowed in the interface block are functions that can be referenced as defined operations.

The initial line for such an interface block takes the following form:

INTERFACE OPERATOR (op)

op

Is one of the following:

  • A defined unary operator (one argument)

  • A defined binary operator (two arguments)

  • An extended intrinsic operator (number of arguments must be consistent with the intrinsic uses of that operator)

The functions within the interface block must have one or two nonoptional arguments with the INTENT(IN) and/or the VALUE attribute, and the function result must not be of type character with assumed length. A defined operation is treated as a reference to the function.

The following shows the form (and an example) of a defined unary and defined binary operation:

Operation

Form

Example

Defined Unary

.defined-operator. operand1

.MINUS. C

Defined Binary

operand2 .defined-operator. operand3

B .MINUS. C

1 The operand corresponds to the function's dummy argument.

2 The left operand corresponds to the first dummy argument of the function.

3 The right operand corresponds to the second argument.

For intrinsic operator symbols, the generic properties include the intrinsic operations they represent. Both forms of each relational operator have the same interpretation, so extending one form (such as >=) defines both forms (>= and .GE.).

The following is an example of a procedure interface block defining a new operator:

  INTERFACE OPERATOR(.BAR.)
    FUNCTION BAR(A_1)
      INTEGER, INTENT(IN) :: A_1
      INTEGER :: BAR
    END FUNCTION BAR
  END INTERFACE

The following example shows a way to reference function BAR by using the new operator:

  INTEGER B
  I = 4 + (.BAR. B)

The following is an example of a procedure interface block with a defined operator extending an existing operator:

  INTERFACE OPERATOR(+)
    FUNCTION LGFUNC (A, B)
      LOGICAL, INTENT(IN) :: A(:), B(SIZE(A))
      LOGICAL :: LGFUNC(SIZE(A))
    END FUNCTION LGFUNC
  END INTERFACE

The following example shows two equivalent ways to reference function LGFUNC:

  LOGICAL, DIMENSION(1:10) :: C, D, E
  N = 10
  E = LGFUNC(C(1:N), D(1:N))
  E = C(1:N) + D(1:N)

See Also