the magics of eof()

CBFalconer cbfalconer at
Fri Dec 17 20:37:48 CET 2004

Francesco Bonomi wrote:
> I don't know if what I found is a bug or a correct behaviour I
> don't understand.
> The following  program halts with error 'attempt ro read past
> end of file';
> program test;
> var
>   f : file of char;
> begin
>   rewrite(f,'test.dat');
>   seek(f,0);
>   f^:='x'; (*GIVES ERROR HERE*)
>   put(f);
>   close(f);
> end.

Read the definitions of file state in the standard.  As far as ISO
7185 is concerned, a seek is an extension.  At any rate, rewrite
has created a new file, positioned it at eof, and no reading is
possible.  The seek has probably created an anomalous condition in
which reading is actually possible, and using lazy i/o has marked
the file as having a get pending.  Use of f^ says that that get
must be implemented, but the file is at eof and cannot do so.

> If I just insert a call reading eof(f) everything seems to work:

"seems" is the appropriate word.  Read the ISO10206 standard, which
adds extensions allowing you to have this sort of random access. 
At any rate, reading from an empty file should still trigger an

Chuck F (cbfalconer at (cbfalconer at
   Available for consulting/temporary embedded and systems.
   <>  USE worldnet address!

More information about the Gpc mailing list