Why is fflush () not considered safe?

Why fflush()is it not considered safe? I was told that it shows undefined behavior? If so, what is the alternative to fflush ()?

+3
source share
2 answers

You were probably told that fflush(stdin)is undefined and that is correct. But fflush- this is the way for other threads that you want to reset, for example stdout.

To clarify, the stream should be used for output. The standard says:

If the stream indicates an output stream or an update stream in which the last operation was not entered, the fflush function calls the unwritten data for this stream, which must be delivered to the host environment for writing to a file; otherwise, the behavior is undefined.

"Unspecified behavior":

fflush ,

+7

.

fflush() undefined C / , POSIX , , , .

fflush() , fflush(stdout), . ( , ).

, fflush , , , , '\n' EOF. , , fgets - , .

+5

All Articles