首页 > 解决方案 > 嵌套可分配组件

问题描述

当我尝试使用可分配组件嵌套派生类型时,我在 gfortran 7 和 8 中发现了一个奇怪的行为。

这是 Gfortran 中的错误还是标准禁止的?我的理解是否正确,唯一的解决方法是改用指针?

module test_mod
    implicit none
    private
    public :: A_t, C_t

    type :: A_t
        integer, allocatable :: x(:)
    end type

    type :: B_t
        integer :: x
    end type

    type :: C_t
        ! this works
!         integer, allocatable :: S(:)
        ! this works
!         type(B_t), allocatable :: S(:)
        ! this does not work
        type(A_t), allocatable :: S(:)
    end type

contains

end module

program test_allocatable_compoenten
    use test_mod, only: A_t, C_t
    implicit none

    block
        type(C_t) :: orbs

        orbs = C_t()
    end block
end program

标签: objectfortrangfortranallocation

解决方案


推荐阅读