存在属性是否“继承”了派生数据结构的组件?标准规定,如果不存在相应的实际参数,则不存在虚拟参数。但我不确定这如何适用于派生数据类型的组件,如下例所示:
program test
implicit none
type some_type
integer :: acomponent
end type some_type
type(some_type) :: testval
testval%acomponent = 42
call outer()
call outer(testval)
contains
subroutine outer(me)
type(some_type), optional :: me
call inner(me%acomponent)
end subroutine outer
subroutine inner(simple)
integer, optional :: simple
if (present(simple)) then
write(*,*) 'simple present:', simple
else
write(*,*) 'simple not present...'
end if
end subroutine inner
end program test上面的示例使用gfortran-5编译并运行良好,但它是否符合标准?不知怎么的,我看了标准就搞不懂了。
发布于 2016-06-20 02:36:00
示例代码不符合要求。
Fortran 2008标准的相关部分在12.5.2.12p3 (5)中--“不作为基本对象并带有一个或多个子对象选择器的可选虚拟参数不能作为实际参数提供。”
me%acomponent中的组件引用是一个子对象选择器。类似地,如果me是数组,则任何形式的数组下标也将是子对象选择器。
https://stackoverflow.com/questions/37913590
复制相似问题