Hi!
Someone know where is the code of the sprintf implementation in arduino?
i've searched a bit on git and on the included libraries without success
Thanks!
The sprintf() and snprintf() functions are part of the C++ language. They are part of the stdio.h header file.
For what its worth, here is the stdio.h source code.
What is it that you want to know about the function?
masterx81:
Hi!
Someone know where is the code of the sprintf implementation in arduino?
i've searched a bit on git and on the included libraries without success
Thanks!
Are you looking for the actual code or just documentation on the implementation?
It depends on which platform (processor).
The AVR platform has multiple xxprintf() libraries that can be linked in that have varying degrees of implementation.
On the AVR, by default the IDE uses a version that does not include support for floats.
Which platform are you using?
Some have repositories that can be accessed if you want to see the actual code but some do not.
But the ones that don't have their repository often are full implementations of the gnu library code.
--- bill
I'm interested on the actual code, i'm using SAMD 32bit mcu.
For float values, i think that i use the dtostrf function, or the less elegant sprintf splitting in 2 the float number.
I have a function that have a sprintf on it (this function, expands the functionallity of the sprintf adding some customized short codes), where i have as parameters an array of references to actual parameters, and a second array with sizes (i have them in that way because are an expansion of a variadic template parameter pack). I need to reconstruct the parameter before passing it to the sprintf. I've already tried to copy the data pointed to a correct suzed array of uint8_t/char without success (the data is not well interpretated). So i need to know all the cases that sprintf have and reconstruct the byte array to a datatype using an union (it this way all work as it should). I know the datatype by the size and by the % parameter passed.
This is the function that get the parameters:
template <typename... Args>
void Log(const uint16_t LogCode, const Args&... args) {
First i get the number of parameters:
const uint8_t nParams = sizeof...(args);
then i expand the parameter pack to an array of addresses:
uint8_t* arrayParams[]={(uint8_t *)&args...};
and get parameter sizes in byte:
uint8_t arraySizes[]={(uint8_t)sizeof(args)...};
Then from the function "Log" i call the "customized" sprintf:
void Format(const uint8_t nParams = 0, uint8_t* arrayParams[]={0}, uint8_t arraySizes[]={0}) {
In the function "Format" i call the sprintf, with some of the parameters, that must be reconstructed. If i know what datatype the sprintf function expect in every case, as said, i can reconstruct the correct data type before passing it.
And in any case, i like to know what do every function... Would be useful also only the parameters that it can take
I believe most of the non AVR platforms have a full gnu implementation of the xxprintf code so all the added capabilities should be there for the SAMD platform.
I can't quite tell what you doing, but the xxprintf() code has many capabilities.
From vararg versions, to even being able to extend it.
It almost sounds like you may be going about this the hard way.
See the gnu documentation for some more information about customizing and extending the xxprintf functions:
--- bill
I've implemented for example a % parameter that can load another text in PROGMEM. A % parameter that print a date with my regional datetime format, a % parameter that call a function for extract a text from a file in the SD card, and so on...
Thanks for the suggestion!
Whoa, so i can add the handlers to my functions ad use directly the sprintf? Soooo nice!!!
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.