Hello everybody,
I am starting this thread because I encounter a problem with the pointers in Fortran.
I want to use a pointer of an array-valued function, but I get a segmentation fault error during execution (compilation is ok with gfortran).
Everything works well when the pointer aims at a function returning a real. But it fails when the function returns an array of reals. I guess there is a problem in the definition of my pointer, but I don't know what to do.
Here is a small code to illustrate my problem :
Any help would be appreciated.
Thanks.
I am starting this thread because I encounter a problem with the pointers in Fortran.
I want to use a pointer of an array-valued function, but I get a segmentation fault error during execution (compilation is ok with gfortran).
Everything works well when the pointer aims at a function returning a real. But it fails when the function returns an array of reals. I guess there is a problem in the definition of my pointer, but I don't know what to do.
Here is a small code to illustrate my problem :
Code:
program main
implicit none
real*8, external, pointer :: p
p => f1
print*,p(1.0D0) !this is ok
p => f2
print*,p(1.0D0) !I get a segmentation fault
contains
function f1(x)
implicit none
real*8 :: f1
real*8, intent(in) :: x
f1 = x+2
end function f1
function f2(x)
implicit none
real*8 :: f2(2)
real*8, intent(in) :: x
f2(1) = x+1
f2(2) = x-1
end function f2
end program main
Any help would be appreciated.
Thanks.