When I am using a fortran function defined with an array and trying to access the function inside another routine, that is giving segmentation fault. Below is my code.
module abcd
implicit none
contains
real*8 function f(x)
real*8,intent(in)::x(:)
f=sum(x)
end function f
real*8 function funco(f,n)
real*8,external::f
integer,intent(in)::n !dimension of array to be used with f
real*8::y(n)
y=1
funco=f(y)
end function funco
end module abcd
use abcd
implicit none
write(*,*) funco(f,10)
end
Here, I have explicitly defined the array y inside funco, still segmentation fault is coming. My original program is required to use a function that behaves like the function funco. I gave this small example for demonstrating my issue.
fhas a dummy argument of assumed shape, but infuncoyou say that the dummy function has an implicit interface. That's not allowed. Do you know about interfaces?fin the functionfuncoyou'll need to provide an explicit interface forfinfunco; if you want to useexternal finfuncoyou'll need to make the module functionfsuitable to be used with an implicit interface. There's more detail in the linked question and its answers, but a wider search for "explicit interface" will provide many other questions/answers.interfacekeyword. It is a concept denoting that the calling code can see the description of the subroutine or function.