C++, printf() and flushing

I’m using the C++ sample from NET+OS 7.1.

When I use cout it works correctly during debugging (if I step over the statement the whole line is printed on the serial console).

When I use printf it doesn’t print the whole line on the serial console. How can I make printf automatically flush its output?

From the root.cxx:

#ifndef NETOS_GNU_TOOLS
printf(…);
#else
cout << …;
#endif

So the sample uses cout by default, but I need printf.

this is odd. because cout shouldn’t flush it’s cache also. for flushing you can append “<< endl;” for cout and "
" for printf

You should be able to call
as Daniel states to see the whole output. Also, if you’re calling printf from multiple threads you’ll need to mutex protect the calls to printf, otherwise they’ll stomp on eachother.

In the sample code both printf and cout are using a end of line at the end. (
and endl). So both should flush.

And how do you know that printf needs mutexes if I call it from multiple threads? Can I find that in the documentation somewhere?

I’m still having problems with flushing. I have a breakpoint on the first line in applicationStart() and this is what I get on the serial port:

IAM:Got AUTO-CONFIGURED IPv6 address FE80::240:9DFF:FE43:3597 on interface eth0:3
IAM:Got DHCP IPv4 address 1

I first have to printf() something myself before it continues with
“30.144.45.14 on interface eth0
Network IP configured.”

I’m not aware of any place in the documentation that specifies this (and a quick search of the API reference confirms this). I know this, however, from speaking with Digi’s Engineering team about a case a few months back.

Does this happen with one of the template apps or just your own custom app? If only on yours, what changes have you made?

It happens with the C++ sample.
The breakpoint is on the line

 app_down.Name(app_name);