Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

glibc - Do any functions in the C standard library implicitly use `stderr`?

The C spec mandates all C programs have 3 streams open and available to them: stdout, stdin, stderr.

The users can use these streams as they see fit, e.g.:

fprintf(stdout, "lol");
fputs("oops", stderr);
fgets(buffer, 20, stdin);

Some functions in the C standard library implicitly use these, e.g.:

printf("lol");           /* implicitly uses stdout */
puts("rofl");            /* implicitly uses stdout */
int c = getchar(buffer); /* implicitly uses stdin  */
  1. Do any functions in the C standard library implicitly use stderr?
  2. Do any functions in common implementations of the C standard library (eg. GNU's glibc on Linux) implicitly use stderr?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The assert macro and the perror function write to the standard error stream. So does the abort_handler_s function (in optional Annex K).

exit closes files and flushes streams, so it implicitly acts on the standard error stream. _Exit and abort may do so; the C standard permits but does not require it. fflush(NULL) flushes all streams.

C 2018 7.21.3 3 describes some interaction between input and output streams: Requesting input on an unbuffered stream or on a line buffered stream and that requires characters from the host environment, then line buffered streams are flushed. This may affect the standard error stream.

Per C 2018 Annex J, which is optional, the C implementation may write some floating-point diagnostics to the standard error stream as part of normal program termination.

Searching for “standard error stream” and “stderr”?in the C 2018 standard does not reveal any other implicit uses of the standard error stream in the standard library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...