[Courses] Re: [C] A clarification on fflush(stderr)

Anand R anand.r at cybertech.co.in
Sat Aug 10 19:03:10 EST 2002


Hi Team,
 
            This is a wild wild guess ;-) Is it used to address systems
which have stderr line buffered or otherwise ? Are we looking at creating
portable code here?? Flushing stderr is harmless. And on systems which may
have line buffered stderr, this might help. What do you think??
 
Thanks,
Andy
 
                
 
            

-----Original Message-----
From: Sneha [mailto:sneha at vit.ac.in]
Sent: Friday, August 09, 2002 8:34 AM
To: Linuxchix
Subject: Re: [Courses] Re: [C] A clarification on fflush(stderr)


Hi all :)
 
Laurel Fan's example was of gr8 help ...thank u....
 
#include<stdio.h>
main()
{
    char buff[BUFSIZ];
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered..........(1)\n");
    sleep(5);
    fprintf(stderr,"stderr is unbuffered........(1)\n");
    sleep(5);
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered..........(2)\n");
    sleep(5);
    fprintf(stderr,"stderr is unbuffered........(2)\n");
    sleep(5);
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered & flushed........(1)\n");
    fflush(stderr);
     sleep(5);
}        
 
** This code makes me think a lot...
if I use setbuf, stderr becomes buffered, the next statement without setbuf
is bringing stderr to itz normal unbuffered state...so, I believe fflush is
not an essential statement to be added when stderr is used, unless or
otherwise if stderr is made buffered using setbuf ...which I have specified
in my last statements....
 
happy day!!!
ba bye
friendly
sneha :o)
 
Teach, Explain, not convinced, just confuse.....
sneha
 
----- Original Message ----- 
From: Laurel Fan < laurel at sdf.lonestar.org <mailto:laurel at sdf.lonestar.org>
>
To: < courses at linuxchix.org <mailto:courses at linuxchix.org> >
Sent: Friday, August 09, 2002 6:49 AM
Subject: Re: [Courses] Re: [C] A clarification on fflush(stderr)

> On Thu, Aug 08, 2002 at 08:40:33PM -0400, Christopher James Lahey wrote:
> > On Thu, 2002-08-08 at 17:10, Laurel Fan wrote:
> > > That's strange.  stderr on my system is unbuffered, unless there's
> > > something wrong with this code:
> > > 
> > > #include <stdio.h>
> > > 
> > > int main()
> > > {
> > >    fprintf(stderr, "stderr is unbuffered");
> > >    sleep(60);
> > > }
> > 
> > Might it be line buffered?  What happens if you put a \n at the end of
> > the string?
> 
> I'm pretty sure it's not line buffered.
> 
> It is unbuffered, which means it printed "stderr is unbuffered" right
> away.  If it was line buffered, it would not print "stderr is
> unbuffered" right away.
> 
> I imagine putting a \n at the end of the string would cause it to
> print a newline.
> 
> -- 
> laurel at sdf.lonestar.org <mailto:laurel at sdf.lonestar.org> 
> http://dreadnought.gorgorg.org <http://dreadnought.gorgorg.org> 
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org <mailto:Courses at linuxchix.org> 
> http://mailman.linuxchix.org/mailman/listinfo/courses
<http://mailman.linuxchix.org/mailman/listinfo/courses>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://linuxchix.org/pipermail/courses/attachments/20020810/462bdbde/attachment.xhtml


More information about the Courses mailing list