这编译正确:
type t1
integer :: a, b(2), c
end type t1
type(t1), parameter :: t1a = t1(1, [2, 3], 4)
我想写这样的东西,除了它不编译:
type t2
integer :: a
integer, allocatable :: b(:)
integer :: c
end type t2
type(t2), parameter :: t2a = t2(1, [2, 3], 4) ! compile error
type(t2), parameter :: t2b = t2(1, [2, 3, 4], 5) ! compile error
gfortran 错误信息
Error: Invalid initialization expression for ALLOCATABLE component 'b' in structure constructor
没有给我任何关于正确语法的线索。
我没有收到任何关于尝试使用可分配类型声明参数变量的抱怨,所以我认为必须有某种方法来初始化它!