3 ms·
Ask HN: When did fflush got defined for stdin as well?
Today I checked the man for fflush and this surprised me:
For output streams, fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underly
ing write function. For input streams, fflush() discards any buffered data that has been fetched from the underlying file, but has not
been by the application. The open status of the stream is unaffected.
I remember it very clearly fflush was defined only for output streams.
I looked at my copy of K&R and K&R defines it as such:
int fflush(FILE *stream)
On an output stream, fflush causes any buffered but unwritten data to be written; on
an input stream, the effect is undefined. It returns EOF for a write error, and zero
otherwise. fflush(NULL) flushes all output streams.
When did the change happen?
- burgerbrain 15y agoRead further down in your manpage: CONFORMING TO C89, C99, POSIX.1-2001, POSIX.1-2008. The standards do not specify the behavior for input streams. Most other implementations behave the same as Linux.
- irahul 15y agoOh, thanks. The earlier version of the man page had output stream in the description(if my memory isn't failing me). I searched for fflush C99 and based on absence of any credible link, I assumed nothing has changed in C99(and nothing really has changed as far as standards go).