简体   繁体   中英

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

From Ubuntu man page stdin(3) :

extern FILE *stdout;

From mingw64 stdio.h file:

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

Both suggest that the value of stdout (a pointer) can not be assumed to be constant.

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):

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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