Quick stdout unbuffered question

This is a discussion on Quick stdout unbuffered question within the C Programming forums, part of the General Programming Boards category; If you set stdout to be unbuffered: setvbuf(stdout,NULL,_IONBF,0); Would there be any reason to use fflush(stdout) ? Thanks you guys ...

  1. #1
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656

    Quick stdout unbuffered question

    If you set stdout to be unbuffered:
    setvbuf(stdout,NULL,_IONBF,0);
    Would there be any reason to use fflush(stdout)?

    Thanks you guys :]

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    For unix this does just what you'd expect - outputs a few characters then pauses 1 second.
    This means extra work for the kernel, by the way.

    Code:
    #include <stdio.h>
    
    int main()
    {
        setvbuf(stdout,NULL,_IONBF,0);
        for (unsigned int i=0;i<10;i++)
        {
            fprintf(stdout,"%d..",i);
            sleep(1);
        }
        fprintf(stdout,"\n");
        return 0;
    }
    .. fflush(stdout) is pointless in this context. Dunno for sure what Windows does...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21