Hi,
Believe I have discovered a compiler issue with FPC 3.0.4. This program illustrates it:
program test(output);
label 99;
type byte = 0..255;
var f: file of byte;
b: byte;
i: integer;
begin
rewrite(f);
for b := 1 to 10 do write(f, b);
reset(f);
for i := 1 to 10 do begin
if eof(f) then begin
writeln('End of file');
goto 99
end;
read(f, b);
write(b:1, ' ')
end;
99:
end.
C:\scratch>fpc -Miso test.pas
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
Linking test.exe
30 lines compiled, 0.1 sec, 29712 bytes code, 1300 bytes data
C:\scratch>test
1 2 3 4 5 6 7 8 9 End of file
IE, it reads 9 values from the file and then indicates EOF even though the file is not, in fact at EOF. In fact, if you comment out the EOF test in the code it works fine, so the EOF indication is apparently false.
I suspect this is an issue with file buffer handling (Lazy I/O).
I'd be interested in hearing about a workaround, this is stopping the port of P5 to FPC.
Thanks!!
Scott Franco