Re: Need interpretation



Here is another program that sometimes gives odd results.

program eof
implicit none
integer i, ierr
character(len=*), parameter :: cmft='(i1)'
open(unit=10,file='temp.dat')
rewind 10
write(10,cmft) 1
write(10,cmft) 2
rewind 10
read(10,cmft) i
read(10,cmft) i
read(10,cmft,iostat=ierr) i ! this should generate an eof error
write(*,*) 'ierr=', ierr, ' (should be negative)'
backspace 10 ! backspace over the end-of-file
backspace 10 ! backspace over the "2" record
read(10,cmft) i
write(*,*) 'i=', i, ' (should be 2)'
end program eof

I think "2" should be the output on the last line, but some
compilers don't handle the implicit endfile correctly and they print
out "1" instead. My version of gfortran happens to print out "0",
which is just an outright error I think.

Is it correct that the standard does define what the above program
should write in that last write statement?

$.02 -Ron Shepard
.