This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/52387] I/O output of write after nonadvancing read
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 29 Feb 2012 13:02:21 +0000
- Subject: [Bug fortran/52387] I/O output of write after nonadvancing read
- Auto-submitted: auto-generated
- References: <bug-52387-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52387
--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-29 13:02:21 UTC ---
I think it get's even messier with the following, simpler looking code, which
consists of four variants (without read/with nonadvanced read -- and with
advanced/nonadvanced write):
OPEN (10, FILE='XXX', status='replace')
WRITE(10, '(a)') 'ABCDEFGHIJKL'
WRITE(10, '(a)') '1234567890ab'
close (10)
OPEN (10, FILE='XXX', position='REWIND', status='old', &
action='readwrite') ! or 'write'
! READ(10, '(tr4)', advance='no') ! << add optionally
WRITE (10, '(A)', ADVANCE='NO') 'mnop' ! << optional advance == 'yes'
call FLUSH (10)
call system ('cat XXX; echo "<"')
close(10)
call system ('cat XXX; echo "<"')
end
[With "call flush"->"flush", "system"->"execute_command_line", it should be
F2008 standard conforming.]
-----------------------------------------
With the Cray/Open64/Pathscale compiler, one gets for instance the following:
Without READ:
mnopEFGHIJKL
1234567890ab
<
mnop
<
And with READ (and also with advance='yes') [that's Bobs example, presumably
with the output he expects]:
ABCDmnopIJKL
1234567890ab
<
ABCDmnopIJKL
<
However, without READ and advance='yes' for WRITE, one gets:
MNOP
FGHIJKL
1234567890ab
<
MNOP
<
-----------------------------------------
By contrast, gfortran has for WRITE:
MNOP<
MNOP
<
And for READ:
ABCDMNOP<
ABCDMNOP
<
That's for advance='no'. With advance='yes', each line ends with a line break.