You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So which one do you propose: stderr should not be buffered?
stderr is not buffered on Linux. stdout is buffered until it finds '\n'.
Regarding OCaml, The manual does not mention its stderr is buffered, but it does mention that prerr_endline and prerr_newline flush the buffer. So I would take it as a design choice that ocaml buffers string (even string with \n) in stderr and provides two functions for you to flush the buffer.
In general I think there is an expectation among programmers that an output named stderr is unbuffered. I think this is reasonable given the use cases for stderr.
Also, the buffered nature of stderr is bubbling up to the other library functions including Jane Street's eprintf. As a result I have to force a flush on every write when using stderr for the commonest use cases.
Based on this I would make stderr unbuffered in the same way as c, c++ and python
Original bug ID: 7177
Reporter: sbleazard
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2017-02-20T10:46:26Z)
Resolution: duplicate
Priority: normal
Severity: minor
Platform: Dell
OS: CentOS
OS Version: 6.6
Version: 4.02.3
Target version: undecided
Category: standard library
Duplicate of: #6973
Monitored by: @diml @hcarty
Bug description
stderr is buffered when using some prerr.. functions. This appears to be the opposite to the normal expectation for stderr
Steps to reproduce
let () =
prerr_endline "foo";
prerr_string "foobar\n";
Unix.sleep 5
foo will print out but foobar will not until after the sleep. The C version works, printing foofoobar before the sleep:
#include <stdio.h>
main(int argc, char **argv)
{
fprintf(stderr, "foo");
fprintf(stderr, "foobar\n");
sleep(5);
}
The text was updated successfully, but these errors were encountered: