考虑以下代码:
subroutine tao_show_this ()
implicit none
type b_struct
integer, pointer :: good_user => null()
end type
type a_struct
type (b_struct), allocatable :: value_ptr(:)
end type
type (a_struct) a
a = a_struct()
end subroutine
使用 gfortran 5 或 7 编译给出:
gfortran -c test.f90
test.f90:4:13:
type b_struct
1
Error: The rank of the element in the structure constructor at (1) does not match that of the component (0/1)
这段代码用 ifort 编译得很好。这是 gfortran 错误还是我的代码有问题?
对于默认结构构造函数,能够省略可分配组件的值是 Fortran 2008 中引入的一项功能。
gfortran 确实目前不支持该功能(“未实现的功能”)。
保留未分配的组件,同时仍为引用的构造函数提供值null
:
a = a_struct(NULL())
正如 DavidS 评论的那样,这存在于报告的错误.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)