Ben Pfaff <[EMAIL PROTECTED]> writes: > ISO C89 and C99 say that fflush(stdin) yields undefined behavior, > so I'm inclined to agree.
It's more complicated than that, I'm afraid. Here's how I remember it; I haven't checked the actual documents. In the late 1980s the POSIX committee decided that fflush (stdin) should flush the input buffer and (on seekable devices) restore the input position on the underyling file descriptor to match the position in the stream. At some point in the mid-1990s this requirement was weakened to be more like (but not exactly like) ISO C89. However, in the latest POSIX it's stronger again, and is more like the late 1980s. Part of the problem is that this area is so complicated that almost nobody other than standards nerds understands the wording. (And most of them probably don't understand it either.....) Anyway, for what it's worth I think fflush (stdin) should behave like 1988 POSIX and glibc, at least for apps that care about this sort of thing.