具有隐式类型的Fortran SAVE属性

时间:2013-10-31 16:42:43

标签: fortran fortran90

我试图编译以下内容,gfortran和ifort都报告了语法错误:

module test
implicit real*8 (a-h,o-z)
allocatable, save :: A(:)
end module test

这是gfortran -c test.f90输出:

allocatable, save :: A(:)
            1
Error: Invalid character in name at (1)

ifort -c test.f90输出:

test.f90(3): error #5277: Syntax error, found ',' following statement keyword
allocatable, save :: A(:)
------------^
test.f90(3): error #5082: Syntax error, found '::' when expecting one of: ( , <END-OF-STATEMENT> ; [
allocatable, save :: A(:)
------------------^
compilation aborted for test.f90 (code 1)

但是,如果没有save属性,或者通过添加显式类型,它编译得很好:

module test
implicit real*8 (a-h,o-z)
allocatable :: A(:)
end module test

module test
implicit real*8 (a-h,o-z)
real*8, allocatable, save :: A(:)
end module test

由于两个编译器都报告了语法错误,我想知道这是不是一个bug,或者是否有人知道可能出错的地方?

1 个答案:

答案 0 :(得分:4)

这不是一个错误。从最新的Fortran标准(或Metcalf,Reid和Cohen,更易读的形式)的5.4.2节,allocatable语句可以使用以下形式:

allocatable [::] array-name [ (array-spec) ] [, array-name [ (array-spec) ]] ...

因此,您必须在单独的语句中使用allocatablesave。您使用的两个编译器报告了错误,因为他们期望allocatable之后的数组名称,但是他们遇到了逗号。