lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 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:
http://stackoverflow.com/questions/5229096/does-printf-always-flush-the-buffer-on-encountering-a-newline
C99, 7.19.3 Files, paragraph 7 and 5.1.2.3/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:

#include <stdio.h>
int main()
{
    //setvbuf(stdout, (char *) NULL, _IOLBF, 0);
    while (1)
    {
        printf("toto\n");
        sleep(1);
    }
    return 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 :)

 -C