https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92100
Bug ID: 92100 Summary: Formatted stream IO irreproducible read with binary data in file Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: angus at agibson dot me Target Milestone: --- Created attachment 47036 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47036&action=edit Reproducing example I have a file with mixed ASCII/binary data (a GMSH 4.1 file). Reading an ASCII line which is followed by binary data from this file with access="stream" and form="formatted" works as expected. However, if I save the file position before the read, and try to repeat the read by passing pos=saved_pos, the result differs. e.g. for the code below, on the attached test problem: first read: $MeshFormat re-read: When I would expect to read the same data both times. I can get around this by inserting a rewind statement before the second read. program stream_test implicit none character(len=20) :: buf integer :: saved_pos open(42, file='test.txt', action='read', access='stream', form='formatted') inquire(42, pos=saved_pos) read(42, *) buf print *, 'first read: ', trim(buf) ! try to re-read from the same position ! rewind(42) ! behaves as expected read(42, *, pos=saved_pos) buf print *, 're-read: ', trim(buf) end program