Re: scanf() quesion?



regis <regis.barbanchon@xxxxxxx> writes:
Keith Thompson wrote:
regis <regis@xxxxxxxxxxxxxxx> writes:

5.1.2.3 Environment (p. 18)

-- The input and output dynamics of interactive devices
shall take place as specified in 7.19.3. The intent of
these requirements is that unbuffered or line-buffered
output appear as soon as possible, to ensure that
prompting messages actually appear prior to a program
waiting for input.

7.19.3 File (p. 270)

[#3] When a stream is unbuffered, characters are intended to
appear from the source or at the destination as soon as
possible. Otherwise characters may be accumulated and
transmitted to or from the host environment as a block.
When a stream is fully buffered, characters are intended to
be transmitted to or from the host environment as a block
when a buffer is filled. 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. Furthermore, characters are intended to be
transmitted as a block to the host environment when a buffer
is filled, when input is requested on an unbuffered stream,
or when input is requested on a line buffered stream that
requires the transmission of characters from the host
environment.

And see paragraph 7:
At program startup, three text streams are predefined and need
not
be opened explicitly -- _standard input_ (for reading conventional
input), _standard output_ (for writing conventional output), and
_standard error_ (for writing diagnostic output). As initially
opened, the standard error stream is not fully buffered; the
standard input and standard output streams are fully buffered if
and only if the stream can be determined not to refer to an
interactive device.
If standard output refers to an interactive device, it can be either
unbuffered or line buffered. If it happens to be unbuffered, then
something like
printf("prompt: ");
fgets(line, N, stdin);
will work properly (i.e., the prompt will appear before the fgets()
call). If it happens to be line buffered, a call to fflush(stdout) is
required to get the same behavior. Such a call won't do any harm even
if stdout is unbuffered.

The problem I have when I read 7.19.3[#3] is how
the sentence starting with "Furthermore..." should be
linked with the previous sentences, i.e., how the paragraph
would be indented if split into item-lists and sublists.

But, if I read you well, should I understand that
the sentence starting with "Furthermore..."
is a continuation of the case "When a stream is line buffered...",
and should not apply to all three cases mentioned above ?

No, the "Furthermore..." sentence applies to all three. In fact, it
explicitly refers to all three cases:

Furthermore, characters are intended to be transmitted as a block
to the host environment

when a buffer is filled [fully buffered],

when input is requested on an unbuffered stream [unbuffered],

or when input is requested on a line buffered stream that
requires the transmission of characters from the host
environment [line buffered].

Second, how to understand the expression "are indented to"?
Does it free an implementation from any obligation ?

(Intended, not indented).

The sentence in question is:

When a stream is _unbuffered_, characters are intended to appear
from the source or at the destination as soon as possible.

The intent, I think, is that an implementation should satisfy this
requirement unless there's a good reason not to. The phrase "as soon
as possible" isn't precise enough to allow for a strict determination
of whether a given implementation conforms or not.

Also, the expression "can be determined not to refer to":
is the implementation allowed to fail to determine it
when it really is ?

Presumably, yes. Otherwise, it probably would have said

... are fully buffered if and only if the stream does not refer to
an interactive device.

rather than

... are fully buffered if and only if the stream can be determined
not to refer to an interactive device.

The standard (implicitly) recognizes that this determination might not
always be possible.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Questions about buffered streams
    ... Buffer classes are supposed to help us with that, ... even if buffered stream doesn’t immediately call ... then PrintStream converts characters into bytes using specified ... PrintWriter is one of the character-based classes. ...
    (comp.lang.java.programmer)
  • Questions about buffered streams
    ... Buffer classes are supposed to help us with that, ... data and thus don’t necessarelly call underlying system for each byte. ... even if buffered stream doesn’t immediately call ... then PrintStream converts characters into bytes using specified ...
    (comp.lang.java.programmer)
  • Re: scanf() quesion?
    ... characters are intended to ... When a stream is fully buffered, ... when a buffer is filled. ... input), _standard output_, and ...
    (comp.lang.c)
  • Re: scanf() quesion?
    ... this is because the standard output ... stream is typically line-buffered. ... characters are intended to ... when a buffer is filled. ...
    (comp.lang.c)
  • Re: "Read stuff from a file and chop it up to do stuff" code advice wanted.
    ... ;; OUTPUT: T or NIL ... ;; characters (I think it is Unicode at least! ... a stream and an array to hold characters in temp memory. ... ;; resulting string. ...
    (comp.lang.lisp)