gpt4 book ai didi

fortran - 如何使用可分配组件设置名为常量的派生类型的值?

转载 作者:行者123 更新时间:2023-12-04 12:26:22 63 4
gpt4 key购买 nike

这正确编译:

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
没有给我任何关于正确语法的线索。
我对尝试使用可分配类型声明参数变量没有任何提示,所以我认为必须有某种方法来初始化它!

最佳答案

我认为你假设错了。 2008 标准明确禁止初始化可分配实体 (R503/C506),我怀疑它也禁止初始化作为派生类型组件的可分配实体,尽管我找不到章节来支持我的怀疑。

关于fortran - 如何使用可分配组件设置名为常量的派生类型的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32876256/

63 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com