1
如果參數列表具有不同的長度,Fortran 95標準是否允許兩個子例程(或函數)具有相同的名稱?例如,如果參數列表不同,Fortran 95是否允許兩個子例程具有相同的名稱?
subroutine a(i)
! code here
end subroutine a
subroutine a(j,k)
! code here
end subroutine a
如果參數列表具有不同的長度,Fortran 95標準是否允許兩個子例程(或函數)具有相同的名稱?例如,如果參數列表不同,Fortran 95是否允許兩個子例程具有相同的名稱?
subroutine a(i)
! code here
end subroutine a
subroutine a(j,k)
! code here
end subroutine a
不是真的如題所給的,但通過使用interface
:
module a_wrapper
interface a
module procedure a_1
module procedure a_2
end interface
contains
subroutine a_1(i)
! code here
end subroutine a
subroutine a_2(j,k)
! code here
end subroutine a
end module
program test
use a_wrapper, only: a
call a(.....)
end program
另見我回答這個帖子:Passing different set of variables in a FORTRAN subroutine或MSB的回答對這個職位:how to write wrapper for 'allocate'
另一個例子:http://stackoverflow.com/questions/2257248/how-to-write-wrapper-for-allocate –
除了閱讀Alexander Vogt關於INTERFACE的回覆,您應該知道,如果某些參數聲明爲可選,則可以使用不同數量的參數調用子例程。 – Fortranner
@Fortranner:的確如此。你可以在鏈接帖子的回答中找到一個例子;-) –