Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Does NEWLINE always flush stdio buffer? Keywords: stdio printf I/O Message-ID: <18351@mimsy.UUCP> Date: 1 Jul 89 20:08:56 GMT References: <11012@ihlpl.ATT.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 27 In article <11012@ihlpl.ATT.COM> knudsen@ihlpl.ATT.COM (Knudsen) writes: >I'd always understood that printf'ing any string ending in '\n' >(newline) would flush the I/O buffer. Nope. >However, I've found that this will not always flush if stdout has been >redirected to a pipe. Yep. Nor (on 4BSD Unix) a socket (there, a pipe *is* a socket), nor (on any Unix, and any pANS system) any ordinary file. >Does anyone know the "official" rules of the traditional stdio >library? The `official' rule is that `interactive' output (like that going to a terminal or a window) is supposed to be line buffered by default, and that any other output is supposed to be fully buffered by default. An application can decide for itself by using setbuf or setvbuf. I feel the best approach is for applications to set all output files to `fully buffered', and then to use fflush whenever the output is supposed to appear. This never produces surprises, and it also tends to run faster. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris