Paul Eggert <[EMAIL PROTECTED]> writes: > Ben Pfaff <[EMAIL PROTECTED]> writes: > >> ISO C89 and C99 say that fflush(stdin) yields undefined behavior, >> so I'm inclined to agree. > > 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.
Is there a version of POSIX newer than "The Open Group Base Specifications Issue 6: IEEE Std 1003.1, 2004 Edition"? This version doesn't say anything about the behavior of fflush for input streams, or at least it doesn't on the page dedicated to fflush. > 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. If apps want that behavior then it entirely makes sense to implement it (and I really shouldn't have stuck my oar in). I'm surprised that glibc implements this behavior for fflush on input streams: the glibc manual I have here doesn't mention it. But I can see in the libio sources that glibc does do it. -- Ben Pfaff [EMAIL PROTECTED]