https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70684
Bug ID: 70684 Summary: incorrect reading of values from file on Windows Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: ajmay81 at googlemail dot com Target Milestone: --- When writing and then reading back values from a file on Windows (program built with gfortran via mxe cross compiler) the wrong values are read. Here is a trivial example: program test implicit none integer,parameter :: isize=12 integer,parameter :: funit=12 integer :: i double precision, dimension(isize) :: a do i=1,isize a(i)=dble(i) enddo write(6,*)'Value to write' do i=1,isize write(6,*)a(i) enddo open(funit,file='test.txt') write(funit,'(1x,6(f25.20,'',''))') (a(i),i=1,isize) close(funit) do i=1,isize a(i)=0d0 enddo open(funit,file='test.txt') read(funit,*) (a(i),i=1,isize) close(funit) write(6,*)'Values after read' do i=1,isize write(6,*)a(i) enddo end And compiled with: x86_64-w64-mingw32.static-gfortran test.f90 On Linux the values 1-12 are read, but on Windows the values 1-6,0,7-11 are read. It seems that the file is written with Windows line endings on Windows, but when read Linux line endings are expected. I think it should be consistent, at least one should be able to read files back on the same system they are generated. I grepped through a recent 5.3.0 tarball, and it's a bit of a guess but in libgfortran/io/transfer.c the function next_record_r() knows only about '\n' line endings, yet it's opposite number next_record_w() knows about both '\n' and '\r' - so perhaps the same logic just needs copying to the read function?