Path: utzoo!attcan!uunet!mitel!sce!scs!spl1!gargoyle!tank!uxc.cso.uiuc.edu!iuvax!rutgers!bellcore!texbell!nuchat!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: Does NEWLINE always flush stdio buffer? Message-ID: <4861@ficc.uu.net> Date: 3 Jul 89 13:27:06 GMT References: <11012@ihlpl.ATT.COM> <12375@bloom-beacon.MIT.EDU> <10487@smoke.BRL.MIL> Organization: Xenix Support, FICC Lines: 23 In article <10487@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > The proposed ANSI Standard for C suggests (sort of a soft requirement) > what are essentially the current UNIX System V STDIO rules for line-buffered > streams: not only should the output buffer be flushed when a new-line is > encountered or the buffer fills up, but also ALL line-buffered output streams > should be flushed whenever input is requested from an unbuffered stream or > when line-buffered input has to refill its buffer. The cost of implementing > this can be substantial! No, it is not. In fact, if (popping down to the implementations I'm familiar with) _filbuf(stdin) calls _flsbuf(stdout) you get all the advantages of line-buffered output, obviate the need for most explicit fflush() calls, and have almost no overhead. This behaviour was first implemented (to my knowledge) in the Berkeley stdio library, and is (I believe) what the dpANS is referring to. In fact, if you implement smart flushing, you can abandon the overhead of line buffering completely, without breaking any working programs. -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Business: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. Personal: ...!texbell!sugar!peter, peter@sugar.hackercorp.com.