當我編譯我的程序與運行時檢查,我得到以下錯誤(我不知道爲什麼):運行時檢查失敗
ifort -check all test.f90 -o test
./test
forrtl: severe (193): Run-Time Check Failure. The variable 'my_sum$2$_2' is being used without being defined
Image PC Routine Line Source
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000403098 Unknown Unknown Unknown
.
.
.
sum 0000000000403098 Unknown Unknown Unknown
sum 0000000000402EAF Unknown Unknown Unknown
sum 0000000000402DE6 Unknown Unknown Unknown
libc.so.6 00007F7FEB268BE5 Unknown Unknown Unknown
sum 0000000000402CD9 Unknown Unknown Unknown
的代碼是:
program test
implicit none
real(8) :: x
x=my_sum(lambda_i,0,200)
print*,x
contains
function lambda_i(n) result(i)
real(8) :: i
integer,intent(in) :: n
i=dble(n)
end function
recursive function my_sum(f,i,n) result(s)
implicit none
real(8) :: s
integer, intent(in) :: i,n
interface
function f(n)
implicit none
real(8) :: f
integer,intent(in) :: n
end function
end interface
if (n .ge. 0) s=f(n)+my_sum(f,i,n-1)
end function
end program
任何想法?沒有檢查,程序運行正常,除非我達到遞歸限制。
我ifort產生了價值20100,可避免不崩潰(版本14在Windows上)。 Gfortran具有相同的價值,Abosft 2014無法編譯(因爲它希望lambda_i聲明爲外部函數,即使它是內部函數)。如果我將lambda_i「外部化」,我仍然可以獲得20100. –