A generic interface block must specify a generic name, defined operator, or defined assignment in an INTERFACE statement. The generic name is a single name with which to reference all of the procedures specified in the interface block. It can be the same as any accessible generic name, or any of the procedure names in the interface block.
If two or more generic interfaces that are accessible in a scoping unit have the same local name, they are interpreted as a single generic interface.
Whenever a generic procedure reference is made, only one specific procedure is invoked. The following rules ensure that a generic reference is unambiguous.
If two procedures in the same scoping unit both define assignment or both have the same defined operator and the same number of arguments, you must specify a dummy argument that corresponds by position in the argument list to a dummy argument of the other that has a different type, kind type parameter, or rank.
Within a scoping unit, two procedures that have the same generic name must both be subroutines or both be functions. Also, at least one of them must have a nonoptional dummy argument that both:
When an interface block extends an intrinsic procedure (see the next section), the above rules apply as if the intrinsic procedure consisted of a collection of specific procedures, one procedure for each allowed set of arguments.
+-------------------------------IBM Extension--------------------------------+
Notes:
+----------------------------End of IBM Extension----------------------------+
PROGRAM MAIN INTERFACE A FUNCTION AI(X) INTEGER AI, X END FUNCTION AI END INTERFACE INTERFACE A FUNCTION AR(X) REAL AR, X END FUNCTION AR END INTERFACE INTERFACE FUNC FUNCTION FUNC1(I, EXT) ! Here, EXT is a procedure INTEGER I EXTERNAL EXT END FUNCTION FUNC1 FUNCTION FUNC2(EXT, I) INTEGER I REAL EXT ! Here, EXT is a variable END FUNCTION FUNC2 END INTERFACE EXTERNAL MYFUNC IRESULT=A(INTVAL) ! Call to function AI RRESULT=A(REALVAL) ! Call to function AR RESULT=FUNC(1,MYFUNC) ! Call to function FUNC1 END PROGRAM MAIN
A generic intrinsic procedure can be extended or redefined. An extended intrinsic procedure supplements the existing specific intrinsic procedures. A redefined intrinsic procedure replaces an existing specific intrinsic procedure.
When a generic name is the same as a generic intrinsic procedure name and the name has the INTRINSIC attribute (or appears in an intrinsic context), the generic interface extends the generic intrinsic procedure.
When a generic name is the same as a generic intrinsic procedure name and the name does not have the INTRINSIC attribute (nor appears in an intrinsic context), the generic interface can redefine the generic intrinsic procedure.
A generic interface name cannot be the same as a specific intrinsic procedure name if the name has the INTRINSIC attribute (or appears in an intrinsic context).
PROGRAM MAIN INTRINSIC MAX INTERFACE MAX ! Extension to intrinsic MAX FUNCTION MAXCHAR(STRING) CHARACTER(50) STRING END FUNCTION MAXCHAR END INTERFACE INTERFACE ABS ! Redefines generic ABS as FUNCTION MYABS(ARG) ! ABS does not appear in REAL(8) MYABS, ARG ! an INTRINSIC statement END FUNCTION MYABS END INTERFACE REAL(8) DARG, DANS REAL(4) RANS INTEGER IANS,IARG CHARACTER(50) NAME DANS = ABS(DARG) ! Calls external MYABS IANS = ABS(IARG) ! Calls intrinsic IABS DANS = DABS(DARG) ! Calls intrinsic DABS IANS = MAX(NAME) ! Calls external MAXCHAR RANS = MAX(1.0,2.0) ! Calls intrinsic AMAX1 END PROGRAM MAIN
A defined operator is a user-defined unary or binary operator, or an extended intrinsic operator (see Extended Intrinsic and Defined Operations). A defined operator must be defined by both a function and a generic interface block.
+-------------------------------IBM Extension--------------------------------+
+----------------------------End of IBM Extension----------------------------+
INTERFACE OPERATOR (.DETERMINANT.) FUNCTION IDETERMINANT (ARRAY) INTEGER, INTENT(IN), DIMENSION (:,:) :: ARRAY INTEGER IDETERMINANT END FUNCTION END INTERFACE END
A defined assignment is treated as a reference to a subroutine, with the left-hand side as the first argument and the right-hand side enclosed in parentheses as the second argument.
+-------------------------------IBM Extension--------------------------------+
The type of one of the arguments can only be of type BYTE when the type of the other argument is of derived type.
When the -qintlog compiler option has been specified, and d1 is numeric or logical, then d2 must not be numeric or logical.
When the -qctyplss compiler option has been specified, if x1 is numeric or logical and x2 is a character constant, intrinsic assignment is performed.
+----------------------------End of IBM Extension----------------------------+
INTERFACE ASSIGNMENT(=) SUBROUTINE BIT_TO_NUMERIC (N,B) INTEGER, INTENT(OUT) :: N LOGICAL, INTENT(IN), DIMENSION(:) :: B END SUBROUTINE END INTERFACE