On Tue, 02 May 2006 14:42:00 -0400
Bob Richards <[hidden email]> wrote:
> John Coppens wrote:
> > program testeof;
> > begin
> > if eof then
> > writeln('EOF found')
> > else
> > writeln('No EOF found');
> > end.
> > This sample program doesn't return till <enter> is pressed.
> That's correct and reasonable. You are terminating your program after
> an EOL (ENTER), If you send it an EOF ^d it also responds reasonably.
> $ ./testeof
> ^d entered at kybd
> EOF found
I see your reasoning, but I do not understand why eof doesn't return
always. The eof is not a 'wait for eof', but a test. If we're _not_ at
the end of the file, the program should return with false, at least how I
if not eof then begin
write('Wait for input ');
the eof call here, makes the program invert it's output, as the eof waits
for the buffer to be filled (so the number is already on the screen) then
outputs the 'Wait for input' text. It doesn't feel right...
I guess the eof call is superfluous here, but it wouldn't be so illogical
if the input channel is redirected (eg. from a file).
> I see your reasoning, but I do not understand why eof doesn't return
> always. The eof is not a 'wait for eof', but a test. If we're _not_ at
> the end of the file, the program should return with false, at least
> how I
> understand it.
It is not possible to know whether you are at the end of a file or
device without (attempting to) read from it (unless you previously
hit the eof marker).