如果参数列表具有不同的长度,Fortran 95标准是否允许两个子例程(或函数)具有相同的名称?例如,
subroutine a(i)
! code here
end subroutine a
subroutine a(j,k)
! code here
end subroutine a
答案 0 :(得分:3)
不是字面上的问题,而是使用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或M.S.B。回答这篇文章:how to write wrapper for 'allocate'