如何在Fortran公共块中使用可分配的字符?

时间:2019-03-10 23:48:41

标签: fortran character fortran-common-block

在Fortran 77中,我试图在一个公共块中包含一个可分配的字符。但是编译器始终会抱怨

  

错误:COMMON属性与(1)处的ALLOCATABLE属性冲突

我的代码是

      subroutine word()
          character (len = :), allocatable :: a
          common /a/ a
          a = 'word'
      end subroutine word

      program main
          character (len = :), allocatable :: a
          common /a/ a
          call word()
          print *, a
      end program main

我看到的唯一使之起作用的方法是不使用allocatable

      subroutine word()
          character * 4 :: a
          common /a/ a
          a = 'word'
      end subroutine word

      program main
          character * 4 :: a
          common /a/ a
          call word()
          print *, a
      end program main

但这会很麻烦,因为我必须提前知道一个字符的长度。

如何使allocatablecommon块中工作?

0 个答案:

没有答案