[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: print stdout and flush
- From: Cuero Bugot <cbugot@...>
- Date: Thu, 26 May 2011 08:08:09 -0700
> Because ANSI C says that stdout is line buffered? At least I thought so but
> some people disagree: http://stackoverflow.com/questions/3723795/is-stdout-line-buffered-unbuffered-or-indeterminate-by-default
> So, yes, perhaps it's best to fflush(stdout) after all, just in case.
Well I was also miss leaded by some posts, but I found another one that have actual references on the C99 specification:
C99, 7.19.3 Files, paragraph 7 and 220.127.116.11/6
Basically it says that at program startup stdout is opened as a full buffered file unless it is connected to an interactive device...
I actually verified this behavior doing a simple&stupid C program:
//setvbuf(stdout, (char *) NULL, _IOLBF, 0);
When running 'test' in a shell shows that the new line appears every seconds
However running 'test > somefile' will not feed the file, unless I uncomment the setvbuff line :)