问题
I need to work on Fortran90 code on my Macbook Pro, which was written on Microsoft Developer Tools years ago. As a free option, I have installed gfortran
on my Macbook to be able to compile it. The original code includes &
continuation character for the long lines but I am not able to use it. Without &
character, everything works fine. What might be the problem? Do I need to activate something to be able to use &
character?
For example, I think something like this should work:
x = 1
y = 2
z = x+
&y
end
But instead, I am having this error. It might be end of line error. How can I solve it?
3:72: Error: Syntax error in expression at (1)
4:9: Error: Invalid character in name at (1)
回答1:
In free-form Fortran, the line continuation character (&
) at the end of the line to be continued. Your code should read:
program test
x = 1
y = 2
z = x+ &
y
end program
This is stated in the Fortran Standard (here: 2008, but applicable as well for Fortran 90), Cl. 3.3.2.4 "Free form statement continuation":
1 The character “&” is used to indicate that the statement is continued on the next line that is not a comment line. [...]
2 If a noncharacter context is to be continued, an “&” shall be the last nonblank character on the line, or the last nonblank character before an “!”. [...]
来源:https://stackoverflow.com/questions/36133324/continuation-in-gfortran-5-2-0