Interface blocks

The interface block allows you to specify an explicit interface for external and dummy procedures. You can also use an interface block to define generic identifiers. An interface body in an interface block contains the explicit specific interface for an existing external procedure or dummy procedure. You can also specify the interface for a procedure using a procedure statement.

Read syntax diagramSkip visual syntax diagram
>>-INTERFACE_statement-----------------------------------------><

Read syntax diagramSkip visual syntax diagram
   .-------------------------------.   
   V                               |   
>>---+---------------------------+-+---------------------------><
     +-FUNCTION_interface_body---+     
     +-SUBROUTINE_interface_body-+     
     '-PROCEDURE_statement-------'     

Read syntax diagramSkip visual syntax diagram
>>-END_INTERFACE_statement-------------------------------------><

INTERFACE_statement
See INTERFACE for syntax details
END_INTERFACE_statement
See END INTERFACE for syntax details
PROCEDURE_statement
See PROCEDURE for syntax details

FUNCTION_interface_body

Read syntax diagramSkip visual syntax diagram
>>-FUNCTION_statement------------------------------------------><

Read syntax diagramSkip visual syntax diagram
>>-+--------------------+--------------------------------------><
   '-specification_part-'   

Read syntax diagramSkip visual syntax diagram
>>-end_function_statement--------------------------------------><

SUBROUTINE_interface_body

Read syntax diagramSkip visual syntax diagram
>>-SUBROUTINE_statement----------------------------------------><

Read syntax diagramSkip visual syntax diagram
>>-+--------------------+--------------------------------------><
   '-specification_part-'   

Read syntax diagramSkip visual syntax diagram
>>-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 ,  3  and  5  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 or with a procedure declaration statement, you specify all the characteristics of the procedure or abstract interface. 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 unless you specify the IMPORT statement. It is treated as if it had a host with the default implicit rules. See Determining Type for a discussion of the implicit rules.

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

The interface bodies within an abstract or specific 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 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.

A procedure name used in a PROCEDURE statement must not have been previously specified in any MODULE PROCEDURE statement in any accessible interface block with the same generic identifier.

IBM extension begins 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. IBM extension ends

Examples

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.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us