0
任何人都可以告诉我为什么这个简单的程序给我一个分段错误?如何在Fortran中的子例程中使用函数?
我正在使用gfortran,我需要在子程序中使用一个函数。
program tst
implicit none
real z,x,y
x=10.
y=2.
call s(10.,10.,z)
print*,z
end program
real function c(x,y)
implicit none
real x, y
c = x*y
return
end
subroutine s(x,y,z)
implicit none
real x, y
real z
real c
z = c(x,y)
end
我试过了,在移动固定格式代码'$ gcc tst.for -o tst -lgfortran &&。/ tst'后回来了'100.000000' Fedora 19,AMD – 2014-10-02 21:27:39
似乎对我很好,但请注意你的子程序在你的程序中是* not *,它们是* external *,这是是相反的。 – 2014-10-03 04:34:07