我试图在 Fortran 77 中的公共块内有一个可分配的字符。但编译器总是抱怨
Error: COMMON attribute conflicts with ALLOCATABLE attribute at (1)
我的代码是
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
街区工作?