On 04.24 R.I.P. Deaddog wrote:
> On 23 Apr 2001, Steve Fox wrote:
> 
> > In this *extremely* simple program, I get no output with
> > bash-2.04-18mdk. If I add a newline char after the string, it works. But
> [snip]
> > int main()
> > {
> >     printf ("This is a test");
> >     return 0;
> > }
> 
> Hmmm.... from a quick test it seems to me that before any prompt is
> displayed the line is cleared and the cursor position is reset to the 1st
> column. But any more qualified people here willing to answer?
> 

In theory, that's the correct behaviour. stdout is buffered, so you only
get output when buffers are flushed. That happens on a newline or
if you manually call fflush(stdout). A libc implementation can choose
to flush buffers on program termination, but do not trust on that.

Perhaps some shell do a change in the behaviour of buffering for file
descriptor 0 when running yout program (ie, set fd<0> unbuffered).

So, in short:
- without fflush() nor \n, behaviour is undefined, but usual is to not
print anything.
- with fflush() of \n, you should get the same kind of output on any shell.

-- 
J.A. Magallon                                          #  Let the source
mailto:[EMAIL PROTECTED]                              #  be with you, Luke... 

Linux werewolf 2.4.3-ac12 #1 SMP Sun Apr 22 10:27:22 CEST 2001 i686


Reply via email to