3 ms·
Needing to manually call flush seems like a major issue, is there a friendlier wrapper in the std lib to print and flush and use some static storage for the buf
by Nail2680 2mo ago
Needing to manually call flush seems like a major issue, is there a friendlier wrapper in the std lib to print and flush and use some static storage for the buffer? Since that seems like it would become step one of any zig project
- eptcyka 2mo agoIt mirrors the C interface.
- metaltyphoon 2mo agoWell, printf flushes when \n is encountered. Does zig have something similar?
- jibal 2mo agoNo, printf does not flush when \n is encountered, unless you specify it with setvbuf(stdout, NULL, _IOLBF, 0); And data files don't generally end with a newline. POSIX buffers aren't generally flushed until fflush or fclose is called (or when the buffer is full). fclose is automatically called on exit(), which is why explicit flushing isn't usually needed. Note that this requires stdio to maintain a global list of open files, which is something that the Zig stdlib doesn't do for numerous good reasons.
- metaltyphoon 2mo ago> No, printf does not flush when \n is encountered, unless you specify it with setvbuf(stdout, NULL, _IOLBF, 0); If stdout is connected to a terminal, it is already line buffered and one doesn’t need to setvbuf at all
- jibal 2mo agoNot relevant.
- PunchyHamster 2mo agoWhy I would want that brought into new language?
- KolmogorovComp 2mo agoI agree, the less batterie-complete STD become, the more everyone get its own half-baked utility one.