[wplug] C code problem

Rick Smith rick at rbsmith.com
Wed Oct 23 17:21:24 EDT 2002


On Wed, Oct 23, 2002 at 05:05:38PM -0400, Rick Smith wrote:
> On Wed, Oct 23, 2002 at 04:05:30PM -0400, Henry Umansky wrote:
> > Can someone explain to me why on my machine the printout value for i is 
> > different.  I compile this with gcc version 2.95.3 20010315.  Can someone 
> > else try compiling this and running it and keep an eye on the two values 
> > that are printed out.
> 
> I can answer this but want to make sure it is not a homework
> assignment or something that is intended for you to figure
> out on your own.  I'll give you a hint: it has nothing to
> do with the compiler.  I'll give you another hint: look
> at the first line.

Hmm, that didn't read quite what it was like when it was in
my head.  Reads like I'm thinking you were being devious.
Sorry about that.

stdout is buffered, stderr is not.
To see the difference fprintf(stderr, "%d : %d\r", i, i)

buffer is flushed when it is full (and maybe some other events,
like timeout).  Because you do \r and overwrite, all you see
is the end of the buffer, which randomly may only update
the first number, with the second number being at the beginning
of the next buffered write.

-- Rick



More information about the wplug mailing list