[comp.lang.c] line buffering

jejones@mcrware.UUCP (James Jones) (05/18/88)

Greetings.  I've entered pilpul mode trying to interpret 4.9.3's description
of "line buffering" of streams.  The sentence in question is

	When a stream is *line buffered*, characters are intended to be
	transmitted to or from the host environment as a block when a
	new-line character is encountered, when a buffer is filled, or
	when input is requested on any line buffered or unbuffered stream.

What I'm wondering about is this: does that last clause mean that whenever
someone does input on *any* line buffered or unbuffered stream, a conforming
implementation should flush buffers on *all* line buffered streams?  (That's
what it seems to say, but it seems like a somewhat unlikely notion.)

The other clauses aren't qualified to show they refer to encounters or
fillings associated with the particular stream in question, so the truly
persnickety could raise the same question about them, but the last clause
is the only one that explicitly says "any...stream."

(Somewhere I have a Stuart Chase book that quotes a city council session
in which the council members thrashed out the precise wording of a leash law.
If I had the book available, I'd quote it--not to make fun of X3J11, whose
members and work I respect, but to point out the difficulties of the medium
they have to work with, i.e. English prose.)

		James Jones

gwyn@brl-smoke.ARPA (Doug Gwyn ) (05/18/88)

In article <700@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes:
>What I'm wondering about is this: does that last clause mean that whenever
>someone does input on *any* line buffered or unbuffered stream, a conforming
>implementation should flush buffers on *all* line buffered streams?

Yes.  (By the way, note that the proposed Standard deals only with a single
program; it does not imply that other processes in a multitasking environment
are affected!)

>... the last clause is the only one that explicitly says "any...stream."

It's intentional.

>(Somewhere I have a Stuart Chase book that quotes a city council session
>in which the council members thrashed out the precise wording of a leash law.

"Dogs shall be kept on leashes while in the park." etc.
You can find this somewhere in Newman's "The World of Mathematics".

mcgrath@tully.Berkeley.EDU.berkeley.edu (Roland McGrath) (05/21/88)

) "Dogs shall be kept on leashes while in the park." etc.
) You can find this somewhere in Newman's "The World of Mathematics".

Oh dear.  Obviously, this explicitly allows that dogs have leashes
attached to their feet (and stay upright).  Also, I doubt any city
ordinances contain the C Standard's specific definition of `shall',
another possible loop-hole.

mcgrath@tully.Berkeley.EDU.berkeley.edu (Roland McGrath) (05/21/88)

The wording is in fact what was really intended.
I had the same question a few months ago when implementing this part of
stdio and Dave Prosser, some flavor of chairperson or somesuch, assured
me that it was really intended.

Anyway, it does make some sense.  You generally want output to stdout
flushed before you read input from stdin, don't you?