0

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.

4
  • The function f has a dummy argument of assumed shape, but in funco you say that the dummy function has an implicit interface. That's not allowed. Do you know about interfaces? Commented May 30, 2020 at 10:22
  • Not actually, never used those. Commented May 30, 2020 at 10:35
  • If you want to use that module function f in the function funco you'll need to provide an explicit interface for f in funco; if you want to use external f in funco you'll need to make the module function f suitable 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. Commented May 30, 2020 at 10:48
  • Be aware that explicit interface is not a piece of code with the interface keyword. It is a concept denoting that the calling code can see the description of the subroutine or function. Commented May 30, 2020 at 17:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.