View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0037950 | FPC | RTL | public | 2020-10-18 14:44 | 2020-10-19 10:53 |
Reporter | Wolfgang Helbig | Assigned To | Jonas Maebe | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | no change required | ||
Platform | imac | OS | os x | ||
Product Version | 3.2.0 | ||||
Summary | 0037950: Buffer is not flushed on textfile other than stdout. | ||||
Description | If you have a text file f other than output, it is buffered like all textfiles but the buffer is not always automatically flushed when the program ends. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
That's correct, you have to close the file for the buffer to be flushed. Files are not automatically closed when a program ends (file handles are closed by the OS, but the buffering happens at a different level). |
|
I cannot reproduce the error with a simple program. But with my real program, the very same last chars of output are always missing. Both programs write a char at a time. And both write the same text. |
|
Even if you call close(f) at the end? Again: you have to manually close files other than output. The compiler/RTL do not do this automatically for you. |
|
Here is a program, that shows the need of flush: {$MODE ISO} program pt; var f: text; begin assign(f, 'out'); rewrite(f); write(f, 'a'); writeln(f); flush(f) end. $ fpc flush.p $ flush $ wc out 1 1 2 out That is 2 bytes, namely a and \lf are properly written to the file out. And here: $ wc out 0 0 0 out w/o the flush. |
|
comparing programs that need the flush with those that don't need a flush I came to the hypothesis that usage of the put procedure defeats buffering and therefore the need for a flush! I do like this approach! But better yet, when this were documented somewhere. |
|
auto flush is only for files in the program statement, e.g. {$MODE ISO} program pt(input,output,f); var f: text; begin assign(f, 'out'); rewrite(f); write(f, 'a'); writeln(f); end. |
|
Thanks, Marco for sharing your knowledge about the fpc implementation. I retested my hypothesis that put is unbuffered. Accidently my test program did have the file in the program header. So it is not put instead of write that makes the flush unnecessary. But I think, the RTS does not do an auto flush but the output is unbuffered if and only if the file occurs in the header. Maybe the MODE ISO might control this as well? |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-10-18 14:44 | Wolfgang Helbig | New Issue | |
2020-10-18 15:03 | Jonas Maebe | Note Added: 0126390 | |
2020-10-18 17:15 | Wolfgang Helbig | Note Added: 0126392 | |
2020-10-18 17:17 | Jonas Maebe | Note Added: 0126393 | |
2020-10-18 17:48 | Wolfgang Helbig | Note Added: 0126396 | |
2020-10-18 18:59 | Wolfgang Helbig | Note Edited: 0126396 | View Revisions |
2020-10-18 19:03 | Wolfgang Helbig | Note Added: 0126403 | |
2020-10-18 21:02 | Marco van de Voort | Note Added: 0126405 | |
2020-10-18 23:05 | Jonas Maebe | Assigned To | => Jonas Maebe |
2020-10-18 23:05 | Jonas Maebe | Status | new => resolved |
2020-10-18 23:05 | Jonas Maebe | Resolution | open => no change required |
2020-10-18 23:05 | Jonas Maebe | FPCTarget | => - |
2020-10-19 10:26 | Wolfgang Helbig | Note Edited: 0126403 | View Revisions |
2020-10-19 10:53 | Wolfgang Helbig | Note Added: 0126412 |