Hi Thomas, when I work on FreeRTOS+TCP, I often wanted to print IP-addresses for logging. Using the above expression with all shifts and AND’s would be cumbersome, a lot of typing. That is why I invented the ‘%xip’ syntax.
There is also a function ntoa(), but that is still not as easy to use as the ‘%xip’ format.
I have also noticed many other printf format specifiers are incorrect (such as %lu for a uint32_t)
Not really, they were incorrect for your compiler, but other compilers liked it this way. Some compilers will print a uint32_t with ‘%x’, others want to see the long flag as in ‘%lx’.
MISRA doesn’t like the use of int, long, unsigned, because those types do not specify the actual width. But using a cast to those those standard types would avoid the printf() format warnings:
/* This will not cause a warning by the compiler,
* but MISRA doesn't like it. */
printf( "IP = %xip\n", ( unsigned ) ulIPAddress );
Earlier you wrote:
I noticed that there are a lot of places, where ntohl() is missing, and sometimes it’s even mixed in the same printf()
The reason is that some IP-addresses in the library are stored in native endian, others in network-endian. And if not, I must have been mistaken, as I used to work mostly on a big-endian platform.
Once your application is ready for production, you may as well undefine FreeRTOS_printf() and FreeRTOS_debug_printf(). That will also stop the compiler warnings.