在 C 中,默认情况下标准输入是什么缓冲状态?

In C what buffering state is stdin by default?

这可能是一个完全错误的问题,或者至少是迂腐的,但我正在研究 K&R,并且正在通读此文档:File input/output

尽管它声明流 具有 缓冲状态,但它没有提及默认情况下标准输入处于什​​么状态。

默认是行缓冲的吗?它是特定于实现的吗?

运行 这段代码似乎表明它是行缓冲的:

#include <stdio.h>

main()
{
    getchar();
}

谢谢

这是一个很好的问题,但答案并不具体。

C 标准明确指出 stdinstdout 在初始状态下是完全缓冲的 当且仅当 (我强调) stream 不是指交互设备。这表明其他任何事情都是未指定的 and/or 实现定义的行为。该标准还规定交互设备的定义是实现定义的。

更新:引用最新标准的相关部分:

C17 § 7.21.3p7:

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

C17 § 5.1.2.3p7:

What constitutes an interactive device is implementation-defined.

C99 和 C11 标准中的语言是相同的,尽管部分编号不同。