简体   繁体   English

可以假设`stdin`,`stdout`和`stderr`的值是常量吗?

[英]Can the values of `stdin`, `stdout`, and `stderr` be assumed to be constant?

From Ubuntu man page stdin(3) : 从Ubuntu手册页stdin(3)

extern FILE *stdout;

From mingw64 stdio.h file: 来自mingw64 stdio.h文件:

#define stdout (&__iob_func()[1])

Both suggest that the value of stdout (a pointer) can not be assumed to be constant. 两者都表明stdout (指针)的值不能被假定为常量。

Can I still rely on something like this to work: 我仍然可以依靠这样的工作:

FILE * stream;

// early after startup
stream = stdout;

// much later, far down the stack, in a different function
fprintf(stream, "%s", "fprintf(stream, \"");

This is what the C11 standard has to say ( §7.21.1-3 ) (accent my own): 这就是C11标准所说的( §7.21.1-3 )(我自己的口音):

stderr 标准错误
stdin 标准输入
stdout 标准输出
which are expressions of type '' pointer to FILE '' that point to the FILE objects associated, respectively, with the standard error, input, and output streams. 它是“ 指向FILE指针 ”类型的表达式,它们分别指向与标准错误,输入和输出流相关联的FILE对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM