Fortran 编译错误:位于(1)的名称中的字符无效
我写 另存为test.f,并使用Fortran 编译错误:位于(1)的名称中的字符无效,fortran,fortran90,gfortran,Fortran,Fortran90,Gfortran,我写 另存为test.f,并使用gfortran-ffree form-Wall-Werror-ffree line length none test.f获得编译错误 program test implicit none integer, parameter :: N = 3 real(8), parameter :: & A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A)
gfortran-ffree form-Wall-Werror-ffree line length none test.f
获得编译错误
program test
implicit none
integer, parameter :: N = 3
real(8), parameter :: &
A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A) ) &
b(N) = (/ 5d0,-3d0,8d0 /)
print *, A
end program
怎么了
编译器是GNU Fortran(GCC)版本6.1.1 在声明
b
之前缺少逗号:
test.f:6:24:
A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A) ) &
1
Error: Invalid character in name at (1)
test.f:9:12:
print *, A
1
Error: Symbol ‘a’ at (1) has no IMPLICIT type
建议:用命名常量替换
real(8)
,比如说,use,instructive::iso_fortran_env,only:wp=>REAL64
,然后声明real(wp)::a(N,N)。
最后,以1.5_wp,2.0e+3_wp
的形式编写文本。
real(8), parameter :: &
A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A) ), &
b(N) = (/ 5d0,-3d0,8d0 /) ! ^
! |
! comma inserted here