作者physicschild (面對未來)
看板Programming
標題[問題] 關於fortran 中 function 的宣告是否每次重讀?
時間Wed Feb 11 12:17:17 2009
主要的問題是每一次主程式呼叫function時,是否會重新宣告並
給予新的初始值。我寫了一了小程式測試了一下:
program test
implicit none
real*8::b
real*8,external :: abx
b=abx(999)
b=abx(123)
stop
end
function abx(z)
implicit none
real*8 :: a=3
real(8) ::abx,z
write(*,*) a
abx=z
a=100
return
end function abx
其中主程式呼叫了兩次function abx,所以我預期兩次輸出結果
應該都是a=3,沒想到執行的結果是a=3,a=100。也就是說第二次
呼叫時並沒有重做宣告中a=3這個動作。請問一下為什麼會這樣?
難道不是每一次呼叫都會當作一個新的開始?還是我有哪些觀念
弄錯了。 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.101.161
→ gilocustom:的確不會重新宣告一次,所以請把a=3另 218.171.169.45 02/12 02:11
→ gilocustom:外放到程式裡面非宣告區的部分。 218.171.169.45 02/12 02:13
→ gilocustom:另外...其實有fortran板(遮臉)。 218.171.169.45 02/12 02:17
→ physicschild:Thanks!140.112.102.129 02/12 10:51