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
, I would multiply the frequency with
, and store it as a whole number
The latest version (V8.2.1) of
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.
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.
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
to support floating point numbers 🙂 ?