Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: fflush(stdin) (was: Re: learning c) Message-ID: <10422@bloom-beacon.MIT.EDU> Date: 8 Apr 89 04:19:36 GMT References: <1091@bnlux0.bnl.gov> <584@greens.UUCP> <6487@bsu-cs.UUCP> <1383@auspex.auspex.com> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Distribution: usa Lines: 34 In article <1383@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) correctly points out that: >..."fflush" doesn't >flush input, so the ANSI standard says nothing new - it says "it flushes >output, we make no claims about input", which reflects current practice >(S5R3's "fflush" appears to flush input, although it's not documented - >which is kind of obnoxious; either it's a useful feature, in which case >it should be documented and supported, or it's a useless one, in which >case it shouldn't have been put in... (Rahul Dhesi made essentially the same point earlier.) The trouble with fflush on an input stream is that it isn't analogous to fflush on an output stream. fflush on an output stream means "do the write right now;" however, no equivalent interpretation is meaningful for an input stream. Packages that I know of that do allow fflush on an input stream instead discard the contents of the buffer, which is very different from what fflush on an output stream does. I'm contemplating adding fabort(FILE *) to my stdio library-- this would discard the buffer contents from an input or output stream, without doing any I/O. For an input stream, this would be equivalent to what those extended fflush'es apparently do, but it avoids the nonportable overloading, while admitting the possibility of an orthogonal operation on an output stream. Once upon a time I wanted such a thing for an output stream, perhaps for use in a control-C handler. (I can't remember now; fabort probably wouldn't have helped anyway.) Comments? Steve Summit scs@adam.pika.mit.edu