Buffered and Unbuffered inputs in C

前端 未结 3 1177
执念已碎
执念已碎 2020-12-05 10:43

Is there any way to figure out whether the input is buffered or unbuffered (Apart from manual pages.)? Cant we figure out by looking a

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 11:28

    ISO/IEC 9899-1999 C99 Language Standard

    5.1.2.3 Program execution

    ...

    5) 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 Files

    ...

    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. Support for these characteristics is implementation-defined, and may be affected via the setbuf and setvbuf functions. ...

    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.

提交回复
热议问题