Re: Need interpretation



Richard Maine wrote:
Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx> wrote:

  [code elided]


read(10,cmft,iostat=ierr) i ! this should generate an eof error


Please note that eof is *NOT* an error.

Well, it COULD be if there is not supposed to be an EOF at that file position...:-)




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?


Yes. And yes, it should be a 2. The first backspace backspaces over the
(possibly virtual) endfile record. The second backspaces over the "2"
record.

I haven't experimented with this in recent years myself, but I've been
told that most compilers get it right these days. I can't vouch for how
accurate that is.



--

Gary Scott
mailto:garyscott@xxxxxxx

Fortran Library:  http://www.fortranlib.com

Support the Original G95 Project:  http://www.g95.org
-OR-
Support the GNU GFortran Project:  http://gcc.gnu.org/fortran/index.html

Why are there two?  God only knows.


If you want to do the impossible, don't hire an expert because he knows it can't be done.


-- Henry Ford
.



Relevant Pages

  • Re: Need interpretation
    ... this should generate an eof error ... The first backspace backspaces over the ... endfile record. ... told that most compilers get it right these days. ...
    (comp.lang.fortran)
  • Re: end-of-record versus end-of-file?
    ... While there might not be a physical endfile record, the standard still ... I used to recall that compilers didn't typically do that, ... do so would be to read until hitting and eof. ...
    (comp.lang.fortran)