Intel® Fortran Compiler 18.0 Developer Guide and Reference

Separate Module Procedures

A separate module procedure is a module procedure that is declared in a separate interface body. To denote separate module procedures, you must specify the keyword MODULE as a prefix in the initial statement of both of the following:

The interface block that contains the separate interface body must be nonabstract.

A separate interface body can be declared in a module or a submodule. The corresponding separate module procedure may be defined (implemented) in the same module or submodule or a descendent of the module or submodule. A separate module procedure can only be defined once.

Usually, the separate interface body is specified in a module and the separate module procedure is defined in a descendent submodule.

In the following example, FOO is a separate module procedure whose interface is specified in module M while the procedure body is defined in submodule A:

module M
  type tt
    real r
  end type tt

  interface
    real module function FOO (arg)
      type(tt), intent(in) :: arg
    end function FOO
  end interface
end module M

submodule (M) A
contains
  real module function FOO (arg) result(res)
     type(tt), intent(in) :: arg
     res = arg%r
  end function FOO
end submodule A

A separate module procedure is accessible by use association only if its interface body is declared in a module and it is public (for example, FOO in the above example). If a separate module interface is declared in a submodule, the module procedure is only accessible in that submodule or its descendent submodules.

A separate module procedure interface body (either in a module or submodule) has access to entities in its host through host association.

NOTE

For an interface body that is not a separate interface body, IMPORT statements are required to make entities accessible by host association. However, IMPORT statements are not permitted in a separate interface body.

The initial statement of a separate module procedure body can take one of the two following forms:

A separate module procedure does not have to be defined. The separate module procedure interface can be used to specify an explicit interface; however, the procedure must not be called.

NOTE

Two modules cannot have USE statements that reference each other because circular reference is not allowed. However, you can solve that problem by putting at least one side of the USEs in submodules. This is because submodules cannot be referenced by use association and the USE statements in submodules are effectively hidden.

Examples

See the examples in SUBMODULE.

See Also