Yes I agree, but look at section 16.9.150 in the standard (2023 final draft). The example given there is
WRITE(10,'(A)') 'New'//NEW_LINE('a')//'Line'
When unit 10 is connected to a formatted stream file, this statement is defined to write a record containing “New” and then another record containing “Line”. In order for that to happen on a windows file system (or any other external file system with this kind of multicharacter line termination convention), a <cr><lf>
sequence must be inserted into the external file. One assumes that somehow the fortran i/o library combines with the new_line()
output to produce this result, but the details of how this happens is not specified by the language standard. If one counts the characters in the external file (say with wc) or looks at the binary contents (say with od), then in one case you would see the one-character sequence and in the other case you would see the two-character sequence.
Look also at section 13.7.4. Here the new_line()
function is required to do the same thing as a a slash edit descriptor, which on a windows file system requires that multicharacter line termination convention.
Something else related to this is Table 18.1. Here the constants C_NEW_LINE and C_CARRIAGE_RETURN are defined as single characters of either kind C_CHAR or of default kind. There is a note that specifies new_line(C_NEW_LINE)
is C_NEW_LINE.
One might imagine a situation where multiple file systems are available, and one write statement writes to a windows file system and another write statement writes to a posix/unix file system. On the former, the multicharacter sequence would be written, while on the latter the single character <lf>
would be written to the external file. I don’t have a windows file system on this computer to test that hypothesis, but I think that is what would happen if I did (and if the fortran compiler supported both file systems).
Also, the standard does not specify what happens when the unit is connected to a normal formatted file (i.e. not opened for stream access). On the computers I use these days, the same thing happens in both cases, they both result in two output records. I think this is an extension, something not specified by the standard. I don’t know what happens on a windows-like file system with a mullticharacter line termination convention in this case, but I’m guessing the same thing will occur.
I don’t think this is an error in the standard, I think it is simply trying the best it can to accommodate multiple file system conventions and also multiple character sets, and this is what we programmers now have to work with.
edit: I was curious what happens with the above write statement when the unit number is replaced with a character array to make it an internal write. The two possibilities are that the whole string is placed into the first element, or that ‘New’ is placed in the first element and ‘Line’ is placed into the second. On two compilers that I tried, they both put everything into the first array element, including the <lf>
character between them, and leave the second element unchanged, the same as occurs with a simple assignment into the first array element. If that element is written out (to a file or to the screen), it is then split into two separate lines. I presume this is standard behavior, I didn’t look it up.