2017-07-07 72 views

回答

1

有兩種可能性,我所知道的:

  1. 將它們添加到通話。
  2. 將這兩個數字移到第三個模塊C中,並在AB中使用這兩個數字。

你已經說過你不想要選項1,但是選項2對你來說可能沒問題。

的(未經測試)的例子是

module A 
contains 
    subroutine readNumbers() 
     use C, only: a1, a2 
     use B, only: theFinalRoutine 
     !code to set a1 and a2 
     call theFinalRoutine 
    end subroutine readNumbers 
end module A 

module B 
contains 
    subroutine theFinalRoutine() 
     use C, only: a1, a2 
     !do some things with a1 and a2 
    end subroutine theFinalRoutine 
end module B 

module C 
    real :: a1, a2 
end module C 

program test 
    use A, only: readNumbers 
    call readNumbers() 
end program test 

這並不總是一個好主意,但它確實有助於避免數據的情況下循環依賴(而不是程序之間的依賴關係)。

+0

除了通過例程的參數列表之外傳遞參數最多是一個可疑的練習。廣泛的實踐,我授予你,但可疑。 –

+0

是的,我絕對同意,選項1是應該如何完成的 - 這只是OP明確要求如何在不增加通話的情況下做到這一點。 –

+0

您可以使用COMMON。 :d – Jack

相關問題