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
?library functions are those functions which reduce our time to write a lengthy code. for example: 1. you want to find the square root of a number...instead of writing the code you can use the function sqrt(); which use the file math.h.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With