[Bug fortran/52387] I/O wrong output with nonadvancing output

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Feb 26 10:13:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52387

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-26 10:02:03 UTC ---
(In reply to comment #0)
>         WRITE (10, '(A)') 'ABCDEFGHIJKL'

At this point, the file contains: "ABCDEFGHIJKL" + <new line>.

>         REWIND 10
>         READ (10, '(TR4)', ADVANCE='NO')
>         WRITE (10, '(TL2, A)', ADVANCE='NO') 'MNOP'

And at that point, the file is trimmed to contain "ABCDMNOP" without <new
line>.


With other compilers (file "XXX"):

NAG has at the end: "ABCDMNOP" plus line break.
g95 has at the end: "ABCDEFGHIJKL" + <line break> + "MNOP" + no linebreak.
pathscale: "ABCDMNOPIJKL" + linebreak.


 * * *

Fortran 2008's C.6.2, paragraph 4 (nonnormative):

"If the next I/O operation on a file after a nonadvancing write is a rewind,
backspace, end file or close operation, the file is positioned implicitly after
the current record before an ENDFILE record is written to the file, that is, a
REWIND, BACKSPACE, or ENDFILE statement following a nonadvancing WRITE
statement causes the file to be positioned at the end of the current output
record before the endfile record is written to the file."


And the paragraph 2 of Clause 9.3.4.2 is the following:

"A nonadvancing input/output statement may position a record file at a
character position within the current record, or a subsequent record (10.8.2).
Using nonadvancing input/output, it is possible to read or write a record of
the 
le by a sequence of input/output statements, each accessing a portion of
the record. It is also possible to read variable-length records and be noti
ed
of their lengths. If a nonadvancing output statement leaves a file positioned
within a current record and no further output statement is executed for the
file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement is
executed for it, the effect is as if the output statement were the
corresponding advancing output statement."

 * * *

At least looking at the normative text (9.3.4.2), I think NAG's result is
correct: Namely, after writing "ABCDMNOP" the record is ended with a record
marker (new line) and then it is trimmed (end file marker is written).

Looking at the nonormative text, I get the conclusion Bob had: Namely that the
result should be "ABCDMNOPIJKL" followed by a new line and the endfile marker.



More information about the Gcc-bugs mailing list