Reputation: 4130
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 */
stderr
?stderr
?Upvotes: 7
Views: 422
Reputation: 222352
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.
Upvotes: 10