>From c.l.f, Richard Maine:

2003 9.2.3.3, "File position after data
transfer", 3rd para

  "For a formatted stream output statement, if no error condition
occurred, the terminall point of the file is set to the highest-numbered
position to which data was transferred by the statement."

Currently, we don't.  The following program shouldn't work:

program main
  implicit none
  character(len=6) :: c
  integer :: i
  open(20,file="foo.txt",form="formatted",access="stream")
  write(20,'(A)') '123456'
  write(20,'(A)') 'abcdef'
  write(20,'(A)') 'qwerty'
  rewind 20
  ! Skip over the first line
  read(20,'(A)') c
  ! Save the position
  inquire(20,pos=i)
  ! Read in the complete line...
  read(20,'(A)') c
  ! Write out the first four characters
  write(20,'(A)',pos=i,advance="no") 'ASDF'
  ! Fill up the rest of the line.  Here, we know the length.  If we
  ! don't, things will be a bit more complicated.
  write(20,'(A)') c(5:6)
  ! Copy the file to standard output
  rewind 20
  do i=1,3
    read(20,'(A)') c
    print '(A)',c
  end do
  close (20)
end program main

It currently prints

123456
ASDFef
qwerty

which is wrong.


-- 
           Summary: Formatted stream I/O write should truncate
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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

Reply via email to