I came across some code today that looks like this:
subroutine sub(hello,world,this,routine,takes,a, &
& crazy,large,number,of,arguments, &
& so,many,that,it,gets,split,across,four, &
& lines)
It seems that the ampersands in the 5th column are in case the user
wants to compile the code with a f77 compiler — My question is whether
this is legitimate (standard conforming) fortran 90 code. I suppose that
it probably isn’t standard conforming f77 code since the trailing ampersands
aren’t in column 73 either…but if they were, would this be a standard way to make free-format and fixed-format compilers happy? In other words, does the fortran 90 standard say that &’s in the middle of a line are simply ignored (or something to that effect)?
The & is the Fortran 90 free-form continuation character. The compiler will behave as if the lines are concatenated by matching the location of the trailing & with the leading & on the next line. Since Fortran is happy to ignore spaces between tokens what you have posted is a way of writing a very long statement across a number of source file lines. (OP probably already knows all this, other readers may not.)
The snippet you show is definitely standard-conforming Fortran 90. The standard defines a trailing & to be the continuation character. If you want to split either a token (such as a variable name) or a ‘character-context’ (such as a string literal) across lines then the line onto which the continuation runs must start with an & and there must be no blanks inserted into the sequence of characters after the line-starting &. I think that what you have posted sneaks into standard-conformity on the grounds that the successive &s might be considered to be not introducing any whitespace into the existing whitespace.
However, the line-starting &s are not required in your snippet.
Your snippet is definitely not standard-conforming fixed-format FORTRAN77. However, most modern Fortran compilers will, unless you instruct them otherwise, take a relaxed view of this sort of ‘not-standard-conforming’ but ‘obvious-what-is-meant’ code and compile it quite happily. Unless, that is, you try something odd like adding free-format code into an existing fixed-format source file, that’s just asking for the compiler to have a hissy fit.
EDIT
My original answer failed to answer OP’s question relating to moving the &s into the 73rd column as a tactic for creating code to keep fixed- and free-form compilation happy. In FORTRAN77 continuation is marked by a character (any character) in column 6 of the continuing line. That version of the language did not require any character at the end of the line being continued. Again, I can’t see anything wrong with putting an & in column 73. As OP pointed out in a comment, fixed-form Fortran ignores any characters in col 73-80, and punched cards (ahh, happy days) had only 80 columns.
But I can’t see anything to recommend this approach either. I think that it is far preferable not to mix free- and fixed-form in the same source file. All the current Fortran compilers will compile both forms in the same compilation. But if you want to go ahead and mix the two, feel free to do so.