我试图编译以下内容,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,或者是否有人知道可能出错的地方?
答案 0 :(得分:4)
这不是一个错误。从最新的Fortran标准(或Metcalf,Reid和Cohen,更易读的形式)的5.4.2节,allocatable
语句可以使用以下形式:
allocatable [::] array-name [ (array-spec) ] [, array-name [ (array-spec) ]] ...
因此,您必须在单独的语句中使用allocatable
和save
。您使用的两个编译器报告了错误,因为他们期望allocatable
之后的数组名称,但是他们遇到了逗号。