heinbali01 wrote on Wednesday, June 10, 2015:
Hi David,
Maybe I’m getting old-fashioned: I’m still avoiding the use of floating point numbers in embedded projects. The reason for doing so isn’t really valid anymore: floating point operations are now often handled high-speed by an FPU, and also often there is enough space to store the bigger numbers.
In stead I use fixed-point numbers such as the 8.24 format to express decibels. That is a number between -128.0000000 and 127.9999999.
Or, for storing an FM frequency of 98.15 MHz
, I would multiply the frequency with 100
, and store it as a whole number 9815
.
The latest version (V8.2.1) of FreeRTOS-Plus/Demo/Common/Utilities/printf-stdarg.c
is pretty complete and well-tested, but it does not support floating numbers.
I have never seen a snprintf() function that is not thread-safe!
I do known that in older versions of GCC, the snprintf() functions were extremely stack-hungry. They could easily use more than 200 bytes of stack. Current GCC implementations are better.
The printf-stdarg.c
uses a small and predictable amount of stack space (about 72 bytes).
That snprintf() function is incompatible in one way: if the result does not fit in the provided buffer, the resulting string will be truncated and it will always be terminated with a zero.
char pcBuffer[5];
int rc = snprintf( pcBuffer, sizeof pcBuffer, "%s", "Hello dear world" );
Will result in :
pcBuffer = "Hell" // terminated with a null
rc = 4
You might want to extend printf-stdarg.c
to support floating point numbers ?
Regards.