Added printf support to the library:
Two simple APIs to use:
Code: Select all
pprintf(Serial, "Use Serial explicitly as a print device...\n");
where the first parameter is anything with a Print class.
Code: Select all
printf("Use Serial by setting it as the system print device...\n");
Any Print class can be set as the default output for the printf statement, which is great for portable code. Just one call and all your output goes to the correct device.
Total memory saving over libc implementation is 19kB of flash and 1kB of RAM. Floating point support adds 900 bytes, and can be compiled out, if required.
There are a few minor deviations from the C spec, but should not affect any common use cases. From the comments, these are the deviations:
1. Output failures are not tracked/counted. Return value is the number of characters
that _should have_ been printed.
2. Limited precision - 64 bit ints are truncated to 32, doubles to floats
3. Floats are cast back to int32 for rendering - if there are two many digits, zeros
are appended (and possibly decimals are reduced) - PRECISION IS LOST ON LARGE FLOATS!
4. targets 32 bit processors, so all modifiers which promote to int are ignored
5. 'a' format is not not complete - optionally compiled out to save space
6. All 'capital letter' formats are handled, even if not valid (translated to lower
7. m$ width/precision are parsed, but treated as unset...
8. floating point precision is limited to 8 decimals
9. 'g' precision interpretation differs from gcc - can't understand gccs interpretation
10. width is limited to 255, precision to 254
I must admit, I am quite pleased with the float->int conversion - code footprint is tiny, with no libgcc linkages. Accurate to 7 significant digits.