View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0035136 | FPC | RTL | public | 2019-02-22 14:48 | 2020-10-18 18:49 |
Reporter | helbig1 | Assigned To | Florian | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | x86_64 | OS | OS X | ||
Product Version | 3.0.4 | ||||
Fixed in Version | 3.3.1 | ||||
Summary | 0035136: The function EOF does not comply to ISO Pascal | ||||
Description | EOF returns true even before the file pointer passes the end of file. | ||||
Steps To Reproduce | Turn on the ISO mode, compile and run the following program: program p; var f: text; begin rewrite(f); f^ := 'a'; put(f); reset(f); if eof(f) then writeln('premature eof'); writeln(f^); if eof(f) then writeln('premature eof'); writeln(f^); if eof(f) then writeln('premature eof'); get(f); if eof(f) then writeln('eof correctly set') else writeln('eof should be set, but isn''t'); end. | ||||
Additional Information | With this error is a show stopper, if you want to use ISO-Pascal. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | 43801 | ||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
This is fixed in 3.2.0. [edit] I do not think your code is ISO compliant and contains errors. I miss input and output parameters for one... |
|
Nice to know, that this bug is fixed in 3.2.0. Thaddy de Koning, you are right, the example program is not ISO compliant. It should list the output parameter, because later I used it when calling the writeln procedure. The program header should read: program p(output); With this fix the program is ISO compliant, isn't it? |
|
In normal FPC "text" files are writeonly. (only typed and untyped files are read/write) https://www.freepascal.org/docs-html/rtl/system/rewrite.html What does ISO say about that R/W status of "text" files? |
|
Textfiles are both readable and writeable, like any other file. All external files have to be listed as parameters in the program header and declared as variables, with the two exceptions "input" and "output". If they occur in the parameter list, they are implicitly declared as textfiles. When the input file is used for the first time, it is automatically opened for reading and when output is used for the first time, it is opened for writing. By the way, this works fine with FPC. |
|
I think I misread your example, doing put and get after a rewrite. I read over the reset() inbetween. |
|
The procedures get and put and the function eof refer to the internal text file f and writeln refers to the external file output. |
|
I am not sure, if the approach I have chosen is correct. If it does not work as expected, please provide more tests. |
|
The eof function works fine with release 3.2.0. The above program does not report premature eof. But get(f) throws runtime error 100 (reading past end of file), which it shouldn't. |
|
What's the expected result when reading past eof with get? Or do you get an premature rte 100 with get? |
|
According to the standard you can safely invoke get(f) as long as eof(f) is false. But f^ will be undefined after the last successful get(f). Here is an example run that shows the FPC-Error: $ cat eof.p {$MODE ISO} program p; var f: file of char; begin rewrite(f); f^ := 'a'; put(f); reset(f); while not eof(f) do writeln(f^); get(f) end {at this point, f^ is undefined} end. $ fpc eof.p $ eof a Runtime error 100 at $0000000109BDD479 $0000000109BDD479 $ According to ISO-Pascal, the runtime error shouldn't be reported. |
|
This is still not fixed in 3.2.0: This program must not stop with runtime error 100! $ cat eof.p {$MODE ISO} program p (output); var f: file of char; begin rewrite(f); f^ := 'a'; put(f); reset(f); while not eof(f) do begin writeln(f^); get(f) end; {at this point, f^ is undefined} writeln(f^) end. $ fpc eof.p $ eof a Runtime error 100 at $0000000100366439 $0000000100366439 But p5 v 1.0 shows another violation from the standard! $ pcom eof.p5 <eof.p P5 Pascal compiler vs. 1.0 1 40 {$MODE ISO} 2 40 program p (output); 3 40 var f: file of char; 4 42 begin 5 3 rewrite(f); 6 7 f^ := 'a'; 7 14 put(f); 8 17 reset(f); 9 19 while not eof(f) do 10 23 begin 11 23 writeln(f^); get(f) 12 37 end; 13 38 {at this point, f^ is undefined} 14 38 writeln(f^) 15 47 end. Errors in program: 0 $ pint eof.p5 P5 Pascal interpreter vs. 1.0 Assembling/loading program Running program a a program complete It should not print the second a, since whenever eof the value of f^ is invalid. |
|
Indeed, it is fixed only in 3.3.1 |
|
See also 0037951 The procedure seek should go one position after the last item. |
|
FPC 3.2.1 as of 2020-10-11 prints a a eof correctly set |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-02-22 14:48 | helbig1 | New Issue | |
2019-02-22 18:02 | Thaddy de Koning | Note Added: 0114348 | |
2019-02-22 18:10 | Thaddy de Koning | Note Edited: 0114348 | View Revisions |
2019-02-22 18:11 | Thaddy de Koning | Note Edited: 0114348 | View Revisions |
2019-02-23 20:56 | helbig1 | Note Added: 0114375 | |
2019-02-24 15:30 | Marco van de Voort | Note Added: 0114384 | |
2019-02-25 13:56 | helbig1 | Note Added: 0114404 | |
2019-02-25 14:28 | Marco van de Voort | Note Added: 0114409 | |
2019-02-25 15:02 | Wolfgang Helbig | Note Added: 0114410 | |
2019-03-01 15:06 | helbig1 | Note Edited: 0114404 | View Revisions |
2019-12-28 11:36 | Florian | Assigned To | => Florian |
2019-12-28 11:36 | Florian | Status | new => resolved |
2019-12-28 11:36 | Florian | Resolution | open => fixed |
2019-12-28 11:36 | Florian | Fixed in Version | => 3.3.1 |
2019-12-28 11:36 | Florian | Fixed in Revision | => 43801 |
2019-12-28 11:36 | Florian | FPCTarget | => - |
2019-12-28 11:36 | Florian | Note Added: 0120099 | |
2020-07-23 18:31 | Wolfgang Helbig | Note Added: 0124281 | |
2020-07-24 22:06 | Florian | Note Added: 0124310 | |
2020-08-04 15:53 | Wolfgang Helbig | Note Added: 0124545 | |
2020-10-11 14:45 | Wolfgang Helbig | Note Added: 0126237 | |
2020-10-11 15:02 | Florian | Note Added: 0126238 | |
2020-10-18 15:03 | Wolfgang Helbig | Note Added: 0126389 | |
2020-10-18 18:49 | Marco van de Voort | Note Added: 0126401 |