Using fflush(stdin)

Simple: this is undefined behavior, since fflush is meant to be called on an output stream. This is an excerpt from the C standard:

int fflush(FILE *ostream);

ostream points to an output stream or
an update stream in which the most
recent operation was not input, the
fflush function causes any unwritten
data for that stream to be delivered
to the host environment to be written
to the file; otherwise, the behavior
is undefined.

So it’s not a question of “how bad” this is. fflush(stdin) is simply not portable, so you should not use it if you want your code to be portable between compilers.

Leave a Comment