I’ve been doing some exercises with printing to streams in C.
Today I’ve been a bit confused: as I understand in most implementations of the C standard library, the default behaviour of stdout is block buffered (or line buffered when connected to a terminal), but in my case it seems to be unbuffered.
For example, the following always prints before entering the infinite loop:
# include <stdio.h>
int main() {
fputs("a", stdout);
while (1);
return 0;
}
I can force the behaviour I need by setting setvbuf(stdout, NULL, _IOFBF, 1024);
, but I’m still confused by the default.
Is this expected behaviour when using gcc as provided by mingw-w64, or am I missing something?
Thanks!
Sylvain Brouwer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.