XL Fortran for AIX 8.1

Language Reference


Interface Blocks

The interface block provides a means of specifying an explicit interface for external procedures and dummy procedures. You can also use an interface block to define generic identifiers. An interface body in an interface block specifies the explicit specific interface for an existing external procedure or dummy procedure.



>>-INTERFACE_statement-----------------------------------------><
 
 
   .--------------------------------.
   V                                |
>>---+----------------------------+-+--------------------------><
     +-FUNCTION_interface_body----+
     +-SUBROUTINE_interface_body--+
     '-MODULE_PROCEDURE_statement-'
 
 
>>-END_INTERFACE_statement-------------------------------------><
 
 

INTERFACE_statement
See INTERFACE for syntax details

END_INTERFACE_statement
See END INTERFACE for syntax details

MODULE_PROCEDURE_statement
See MODULE PROCEDURE for syntax details

FUNCTION_interface_body



>>-FUNCTION_statement------------------------------------------><
 
 
>>-+--------------------+--------------------------------------><
   '-specification_part-'
 
 
>>-end_function_statement--------------------------------------><
 
 

SUBROUTINE_interface_body



>>-SUBROUTINE_statement----------------------------------------><
 
 
>>-+--------------------+--------------------------------------><
   '-specification_part-'
 
 
>>-end_subroutine_statement------------------------------------><
 
 

FUNCTION_statement, SUBROUTINE_statement
For syntax details, see FUNCTION and SUBROUTINE.

specification_part
is a sequence of statements from the statement groups numbered (2) and (4) in Order of Statements and Execution Sequence.

end_function_statement, end_subroutine_statement
For syntax details of both statements, see END.

In an interface body, you specify all the characteristics of the procedure. See Interface Concepts. The characteristics must be consistent with those specified in the subprogram definition, except that:

  1. dummy argument names may be different.
  2. you do not have to indicate that a procedure is pure, even if the subprogram that defines it is pure.
  3. you can associate a pure actual argument with a dummy procedure that is not pure.
  4. when you associate an intrinsic elemental procedure with a dummy procedure, the dummy procedure does not have to be elemental

The specification_part of an interface body can contain statements that specify attributes or define values for data objects that do not determine characteristics of the procedure. Such specification statements have no effect on the interface. Interface blocks do not specify the characteristics of module procedures, whose characteristics are defined in the module subprogram definitions.

An interface body cannot contain ENTRY statements, DATA statements, FORMAT statements, statement function statements, or executable statements. You can specify an entry interface by using the entry name as the procedure name in an interface body.

An interface body does not access named entities by host association. It is treated as if it had a host with the default implicit rules. See How Type Is Determined for a discussion of the implicit rules.

An interface block can be generic or nongeneric. A generic interface block must specify a generic specification in the INTERFACE statement, while a nongeneric interface block must not specify such a generic specification. See INTERFACE for details.

The interface bodies within a nongeneric interface block can contain interfaces for both subroutines and functions.

A generic name specifies a single name to reference all of the procedures in the interface block. At most, one specific procedure is invoked each time there is a procedure reference with a generic name.

The MODULE PROCEDURE statement is allowed only if the interface block has a generic specification and is contained in a scoping unit where each procedure name is accessible as a module procedure.

A procedure name used in a MODULE PROCEDURE statement must not have been previously specified in any module procedure statement with the same generic identifier in the same specification part.

+-------------------------------IBM Extension--------------------------------+

For an interface to a non-Fortran subprogram, the dummy argument list in the FUNCTION or SUBROUTINE statement can explicitly specify the passing method. See Dummy Arguments for details.

+----------------------------End of IBM Extension----------------------------+

Example of an Interface

MODULE M
 CONTAINS
 SUBROUTINE S1(IARG)
   IARG = 1
 END SUBROUTINE S1
 SUBROUTINE S2(RARG)
   RARG = 1.1
 END SUBROUTINE S2
 SUBROUTINE S3(LARG)
   LOGICAL LARG
   LARG = .TRUE.
 END SUBROUTINE S3
END
USE M
INTERFACE SS
  SUBROUTINE SS1(IARG,JARG)
  END SUBROUTINE
  MODULE PROCEDURE S1,S2,S3
END INTERFACE
CALL SS(II)              ! Calls subroutine S1 from M
CALL SS(I,J)             ! Calls subroutine SS1
END
SUBROUTINE SS1(IARG,JARG)
  IARG = 2
  JARG = 3
END SUBROUTINE

You can always reference a procedure through its specific interface. If a generic interface exists for a procedure, the procedure can also be referenced through the generic interface.

Within an interface body, if a dummy argument is intended to be a dummy procedure, it must have the EXTERNAL attribute or there must be an interface for the dummy argument.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]