nanoprintf is an implementation of
vsnprintf for embedded systems that, when fully enabled, aims for C11 standard compliance.
nanoprintf makes no memory allocations, uses less than 100 bytes of stack and is implemented within a single header file. It is written in C89 for maximal compiler compatibility and compiles cleanly at the highest warning levels on clang, gcc, and msvc in both 32- and 64-bit modes.
- tinyprintf doesn’t print floating point values.
- “printf” defines the actual standard library
printfsymbol, which isn’t always what you want. It stores the final converted string (with padding and precision) in a temporary buffer, which makes supporting longer strings more costly. It also doesn’t support the
- Also, no embedded-friendly printf projects that I could find are both in the public domain and have single-file implementations.
nanoprintf makes no memory allocations and uses less than 100 bytes of stack. Compiling with all optional features disabled yields ~2.4KB of ARM Cortex-M object code, and compiling with all optional features enabled is closer to 5KB.
nanoprintf is written in C89 for maximal compiler compatibility, and compiles cleanly at the highest warning levels on clang, gcc, and msvc in both 32- and 64-bit modes. C99 or C++11 compilers are required (for
uint64_t and other types) if floating point conversion or large modifiers are enabled, but pull requests that fix this are welcome!
nanoprintf does include C standard headers but only uses them for C99 types and argument lists; no calls are made into stdlib / libc, with the exception of any internal double-to-float conversion ABI calls your compiler might emit. As usual, some Windows-specific headers are required if you’re compiling natively for msvc.
nanoprintf is statically configurable so users can find a balance between size, compiler requirements, and feature set. Floating point conversion, “large” length modifiers, and size write-back are all configurable and are only compiled if explicitly requested, see Configuration for details.