public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102699] New: Stream access input/output
@ 2021-10-12  4:53 xin.liu@compiler-dev.com
  2021-10-12 15:11 ` [Bug fortran/102699] " kargl at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: xin.liu@compiler-dev.com @ 2021-10-12  4:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102699

            Bug ID: 102699
           Summary: Stream access input/output
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xin.liu@compiler-dev.com
  Target Milestone: ---

Consider the following Fortran program:
!------------------------
program streamio
  implicit none
  integer :: k(5) = [5_4, 4_4, 3_4, 2_4, 1_4]

  open(10, file="123.txt", form="formatted", access="stream")
!  open(10, file="123.txt", form="formatted")

  write(10, "(A6)") '098765'
  write(10, "(A6)") '239345'
  write(10, "(A6)") '123789'
  write(10, "(A6)") '789509'
  write(10, "(A6)") '543210'

  rewind(10)

  read(10, "(I2)") k(1)
  read(10, "(I3)") k(2)
  read(10, "(I2)") k(3)
  read(10, "(I3)") k(4)
  read(10, "(I1)") k(5)

  print *,k
end program
!------------------------

Compiled with gfortran 10.1.0.

Regardless of whether the access uses "stream",the result is the same.

the result:

           9         239          12         789           5

the file: 
098765
239345
123789
789509
543210

IMHO, when using access="stream", the result should be 
           9         876          52         393           4
and the file shoule be
098765239345123789789509543210

is it a bug or is there something wrong with my understanding?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/102699] Stream access input/output
  2021-10-12  4:53 [Bug fortran/102699] New: Stream access input/output xin.liu@compiler-dev.com
@ 2021-10-12 15:11 ` kargl at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-10-12 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102699

--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to xin liu from comment #0)

> 
> is it a bug or is there something wrong with my understanding?

I think you may be tripped up by "12.3.3.4 Stream access" where
one finds

P. 213

  While connected for formatted stream access, an external file has
  the following properties.

  *  Some file storage units of the file can contain record markers;
     this imposes a record structure on the file in addition to its
     stream structure. There might or might not be a record marker
     at the end of the file.  If there is no record marker at the end
     of the file, the final record is incomplete.

Followed by "12.3.4.2 Advancing and nonadvancing input/output"

P. 214

   An advancing input/output statement always positions a record
   file after the last record read or written, unless there is an
   error condition.

If I trim your program to

  program streamio
  implicit none
  open(10, file="123.txt", access="stream")
  write(10) '098765'
  write(10) '239345'
  write(10) '123789'
  write(10) '789509'
  write(10) '543210'
  close(10)
  end


the resulting filesize for 123.txt is 30 bytes.   If, instead, I use

  program streamio
  implicit none
  open(10, file="123.txt", form="formatted", access="stream")
  write(10, "(A6)") '098765'
  write(10, "(A6)") '239345'
  write(10, "(A6)") '123789'
  write(10, "(A6)") '789509'
  write(10, "(A6)") '543210'
  close(10)
  end

the resulting filesize for 123.txt is 35 bytes.  So, record markers
are written into the file.  You can probably verify this by using
INQUIRE and POS= after the READs in your original code to see if 
the file is positioned at the start of a record.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-12 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  4:53 [Bug fortran/102699] New: Stream access input/output xin.liu@compiler-dev.com
2021-10-12 15:11 ` [Bug fortran/102699] " kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).