## 8.9.2 Defining Explicit Interfaces

Interface blocks define explicit interfaces for external or dummy procedures. They can also be used to define a generic name for procedures, a new operator for functions, and a new form of assignment for subroutines.

An interface block takes the following form:

  INTERFACE [generic-spec]
  [interface-body]...
  [MODULE PROCEDURE name-list]...
  END INTERFACE [generic-spec]
  generic-spec
  Is one of the following:
  - A generic name
  - OPERATOR (op)

    Defines a generic operator (op). It can be a defined unary, defined binary, or extended intrinsic operator.

  - ASSIGNMENT (=)

    Defines generic assignment.

  interface-body
  Is one or more function or subroutine subprograms. A function must end with END FUNCTION and a subroutine must end with END SUBROUTINE.

  The subprogram must not contain a statement function or a DATA, ENTRY, or FORMAT statement; an entry name can be used as a procedure name.

  The subprogram can contain a USE statement.

  name-list
  Is the name of one or more module procedures that are accessible in the host. The MODULE PROCEDURE statement is only allowed if the interface block specifies a generic-spec and has a host that is a module (or accesses a module by use association).

  The characteristics of module procedures are not given in interface blocks, but are assumed from the module subprogram definitions.

Rules and Behavior

Interface blocks can appear in the specification part of the program unit that invokes the external or dummy procedure.

A generic-spec can only appear in the END INTERFACE statement (a Fortran 95 feature) if one appears in the INTERFACE statement; they must be identical.

The characteristics specified for the external or dummy procedure must be consistent with those specified in the procedure's definition.

An interface block must not appear in a block data program unit.

An interface block comprises its own scoping unit, and does not inherit anything from its host through host association.

A procedure must not have more than one explicit interface in a given scoping unit.

A interface block containing generic-spec specifies a generic interface for the following procedures:

- The procedures within the interface block

  Any generic name, defined operator, or equals symbol that appears is a generic identifier for all the procedures in the interface block. For the rules on how any two procedures with the same generic identifier must differ, see Section 16.2.

- The module procedures listed in the MODULE PROCEDURE statement

  The module procedures must be accessible by a USE statement.

To make an interface block available to multiple program units (through a USE statement), place the interface block in a module.

The following rules apply to interface blocks containing pure procedures:

- The interface specification of a pure procedure must declare the INTENT of all dummy arguments except pointer and procedure arguments.
- A procedure that is declared pure in its definition can also be declared pure in an interface block. However, if it is not declared pure in its definition, it must not be declared pure in an interface block.

Examples

The following example shows a simple procedure interface block with no generic specification:

    SUBROUTINE SUB_B (B, FB)
      REAL B
      ...
      INTERFACE
        FUNCTION FB (GN)
          REAL FB, GN
        END FUNCTION
      END INTERFACE

For More Information:

- On functions, see Section 8.5.2.
- On subroutines, see Section 8.5.3.
- On use and host association, see Section 16.4.1.2.
- On when an explicit interface is required, see Section 8.9.1.
- On when you should not use interface blocks, see your user manual or programmer's guide.
- On defining generic names, see Section 8.9.3.
- On defining generic operators, see Section 8.9.4.
- On defining generic assignment, see Section 8.9.5.
- On modules, see Section 8.3.
- On pure procedures, see Section 8.5.1.2.

Previous Page Next Page Table of Contents