For Programmers: Free Programming Magazines  


Home > Archive > Fortran > October 2006 > Re: Why these original FORTRAN quirks?; Now : Programming practices









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Why these original FORTRAN quirks?; Now : Programming practices
glen herrmannsfeldt

2006-10-30, 7:16 pm

In comp.lang.fortran Rostyslaw J. Lewyckyj <urjlew@bellsouth.net> wrote:
(snip)

> The eof status is determined when you try to fetch the data record
> and needs to be acted on before you try to decode/interpret the
> contents. But you don't want a great deal of extraneous program
> steps (unrelated program execution) between when you inspect the
> eof status and, if not eof, actually look at the data.


Yes. For the PASCAL way you have to test EOF before reading
the (non-existent) data at the end of the file. That is,
EOF tells you that the next read will fail.

> For that reason, I think, it is better to have the eof test be
> an integral part of the READ statement. Though, I am sure, some
> might argue for complete independance. However I can't see anyone
> trying to justify blundering into the interpretation logic before
> testing for the actual availability of data. So it may be the C
> way but I don't believe it's the Fortran way.


I was considering C and Fortran the same. EOF is sensed when
the read fails because no (or not enough) data is available.

This is especially obvious from people translating PASCAL to C,
which often results in processing the last record twice.

C code often uses something like:

while(fgets(buffer,sizeof(buffer),stdin)
) {

which exits the while loop when fgets fails to
read another line of input. Similar Fortran code would
have a READ at the beginning of a loop, with END= to exit.

-- glen
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com