在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
但这会很麻烦,因为我必须提前知道一个字符的长度。
如何使allocatable
在common
块中工作?