John Matthews wrote:
> --- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>> John Matthews wrote:
>>> --- In [email protected], ed <ed@> wrote:
>>>> On Sat, 19 Jul 2008 12:32:23 -0000
>>>> "John Matthews" <jm5678@> wrote:
>>>>
>>>>> --- In [email protected], Thomas Hruska <thruska@> wrote:
>>>>>> kathir resh wrote:  
>>>>>>> since printf is function it returns the no of characters  
>>>>>>> printed...how to view the no of charaters it returns.....
>>>>>> printf("%d\n", printf("Hi!\n"));  
>>>>> Slight variation:
>>>>>
>>>>> printf("%d\n", printf("no of characters = "));
>>>>>
>>>> How do you know when flush is called? It could be after the nested
>>>> function, although it should happen after writing \n, it's
> possible for
>>>> it to happen before the outer printf I believe.
>>> Sorry Ed- not sure I understand. Does it matter when the flush
>>> happens, as long as the characters go into the output stream in the
>>> expected order ie. inner before outer? And isn't that guaranteed by
>>> the inner printf having to be evaluated before the outer executes?
>>>
>>> To be honest I wasn't sure myself whether this 'nesting' of printfs is
>>> ok, but if Thomas thinks it is, that's good enough for me :-)
>>>
>>> John
>> I never really said that it is okay.  I don't generally nest function 
>> calls (line length and the number of parenthesis starts getting kind of 
>> hairy).  But, in this case, I assumed it was for some sort of debugging 
>> purpose.  In which case, it probably is fine.
> 
> It was the specifics of printf I was worried about rather than nesting
> in general.
> 
> I know the inner printf is guaranteed to be evaluated before the outer
> printf, but is that enough to guarantee that the 2 printf arguments
> don't somehow get mixed up in the output stream?

I don't see how that could happen.

As to the issue of flushing - it doesn't matter when the data gets 
flushed.  The exact same data is going to get flushed regardless 
(otherwise C/C++ would be dead languages).  There won't be a random 
newline inserted into the output stream.  Of course, there is no 
guarantee that printf() will flush output after a newline, so you can 
force it to happen with fflush(stdout), if that is a concern.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to