Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Interface and module

petit_lepton
Beginner
408 Views
Dear all,
I encountered a problem between interface and module in the following test program :

module functions
implicit none
contains
function square(x)
real*8 :: x,square
square=x*x
end function square
end module functions

module mod
use functions
implicit none
contains
function launch(x)
interface
function square(x)
real*8 :: x,square
end function square
end interface
real*8 :: x,launch
launch=square(x)
end function launch
end module mod

program test
use functions
use mod
real*8 :: x=2.,y
y=launch(x)
print*, y
end program test

When I compile it, it says that the module mod can not find the function square. But when I get rid off the module functions and put square directly on an independent file, it just works fine...
Can someone tells me what is going on ?
Thanks in advance.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
408 Views
If you are referencing a procedure contained in another module, you must not also define a separate interface for it. The interface comes from the USE of the module. The interface you added in module mod tells the compiler that square is an external procedure, different from the module procedure in module functions.
0 Kudos
Reply