The number and the type of parameters in the function/subroutine invocation will determine actual subroutine/function that will be invoked.
(In C++ parlons, a generic function/subroutine is an overloaded function
|
INTERFACE this_or_that
SUBROUTINE this(x)
integer :: x
END SUBROUTINE
SUBROUTINE that(x)
real :: x
END SUBROUTINE
END INTERFACE
|
|
Example:
PROGRAM main
IMPLICIT NONE
INTERFACE my_function
SUBROUTINE f1(x) ! integer
integer :: x
END SUBROUTINE
SUBROUTINE f2(x) ! real
real :: x
END SUBROUTINE
SUBROUTINE f3(x, y) ! integer, real
integer :: x
real :: y
END SUBROUTINE
END INTERFACE
INTEGER i
REAL r
CALL my_function(i)
CALL my_function(r)
CALL my_function(i,r)
END
|
|
|
INTERFACE
SUBROUTINE f3(x, y)
integer :: x
real :: y
END SUBROUTINE
END INTERFACE
INTEGER :: i = 1
REAL :: r = 3.14
CALL f3(i,r) ! Implicit, with correct order OK
CALL f3(x=i,y=r) ! Explicit, with correct order OK
CALL f3(y=r,x=i) ! Explicit, with wrong order, still OK !!!
CALL f3(r,i) ! Implicit, with wrong order, Not OK...
|
|
INTERFACE my_function
SUBROUTINE f1(x, y) ! <--- my_function(x=i, y=r)
integer :: x
real :: y
END SUBROUTINE
SUBROUTINE f2(y, x) ! <--- my_function(x=i, y=r)
real :: y
integer :: x
END SUBROUTINE
END INTERFACE
|
There is ambiguity because the call
INTEGER i REAL r CALL my_function( x=i, y=r ) |
can invoke either f1() or f2() !!
|