我尝试了以下代码,发现 OPTIONAL 关键字不起作用。编译没问题,但是会提示运行时错误。
我知道通常应该在模块中使用 INTERFACE 来为例程提供足够的信息。我也尝试过,但无论我把接口放在哪里都无法完成编译。
我已经阅读了一些在 TYPE 声明中使用 OPTIONAL 的代码。https://www.pgroup.com/lit/articles/insider/v3n1a3.htm
现在我使用的是intel visual fortran,那有什么区别吗?
module testA_m
implicit none
type :: onion_c
contains
procedure :: testA
end type
contains
subroutine testA(this, a,b)
implicit none
class(onion_c) :: this
real*8 :: a
real*8, optional :: b
write(*,*) a,b
end subroutine
end module
program main
call testIt()
end program
subroutine testIt()
use testA_m
implicit none
type(onion_c) :: onion
real*8 :: c1
real*8 :: c2
c1 = 1.0d0
c2 = 2.0d0
call onion.testA(c1)
end subroutine