FPC compiler issue using -Miso mode lazarus / 64-FPC development ---------------------------------------------------------------------- samiam95124 · 2018-01-02 23:03 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 ---------------------------------------------------------------------- marcov · 2018-01-02 23:25 The file is ten bytes 1 to 10 (see %temp% directory), so that is alright I guess. Which makes it a problem in the reading, not writing, or some buffer sanitation problem. C:\Users\marco\AppData\Local\Temp>hexdump -C fpc_121ADB35.tmp 00000000  01 02 03 04 05 06 07 08  09 0a                    |..........| 0000000a added later: on rereading, you already seem to imply that it is the read ahead. But at least it is certain now. And I tested trunk too, same problem ---------------------------------------------------------------------- rvk · 2018-01-02 23:30 Ieks, labels and goto  Where is the closing of the file? Or is that not needed? (I'm not that familiar with the iso mode) Edit: ah, I see you both concluded it must be in the reading so closing should matter I guess. ---------------------------------------------------------------------- samiam95124 · 2018-01-03 00:58 Marcov, Correct. I dumped the temp file as well and got the same result. Scott Franco ---------------------------------------------------------------------- samiam95124 · 2018-01-03 01:01 Rvk, There is no "close" in ISO 7185 mode. The (all) open files are presumed to be closed on program exit, which of course they are in modern operating systems, even if the language does not support that, the OS closes the files on program exit. The drawback being of course that there is no way to reuse a file, but ISO 7185 has no method for associating to a named file so the point is moot in any case. ---------------------------------------------------------------------- samiam95124 · 2018-01-03 02:19 So I see FPC has a bug tracker, and I filed a bug report for it: 0032938 Thanks! Scott Franco