▲ | Show HN: Uprintf a universal stb-style printf implementation for C (no OS) | |||||||||||||||||||||||||||||||
19 points by Forgret 2 days ago | 16 comments | ||||||||||||||||||||||||||||||||
I've been frustrated by the lack of a truly portable, no-dependency printf for embedded and kernel development. Most solutions are either too bloated or missing key features. So I built Uprintf. It's a single-header library that gives you full printf (flags, width, precision, floats, even custom specifiers) from bare metal to desktop, with zero dependencies or #ifdef hell. Key features: · One header file, no dependencies, no dynamic allocation · Full standard support: %d, %x, %f, %.*s, etc. · Extensible with custom format handlers (add %T for your project) · Configurable: disable floats, set locale, etc. · MIT Licensed. GitHub: https://github.com/Ferki-git-creator/Uprintf I'd love your feedback and contributions! | ||||||||||||||||||||||||||||||||
▲ | s_gourichon 6 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||
Be wary about using an AI that rejects a simple PR (change "return str;" into "return ptr;") based on false statements ("Your PR contains a critical error — the complete removal of return statements from the u_utoa function."). Details on https://github.com/Ferki-git-creator/Uprintf/pull/3#issuecom... I encourage you to continue working on your projects. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
▲ | s_gourichon 17 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Maybe the rabbit hole is much deeper than it seems. Is it really possible to reconcile "no bloat" with "fully standard compliant"? Maybe have a look at https://github.com/eyalroz/printf, if only for the test suite, which looks pretty comprehensive and still fails. Maybe "key features" does not mean the same in all projects, making every project appear "unnecessarily bloated while missing key features" in every other context? | ||||||||||||||||||||||||||||||||
▲ | s_gourichon a day ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Nice. Comprehensive unit tests are indeed welcome. Even a simple test code that tests all features, flags combinations, etc, and outputs a log. It will make easy for anyone to run it and compare the logs. I had a bug:
prints:--42 I may have found an explanation. In u_parse_format(), case 'i': calls u_itoa( value, buffer, 10, false ); which outputs minus sign. Then if ( number ) does if ( sign ) { output_cb( '-', ctx ); chars_written++; } which outputs another minus sign. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
▲ | fjfaase 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Nice work. I always have understood that snprintf does not write a null character when the produced string is longer than the given size. The snprintf function also can be called with a null pointer to calculate the length of the produced string. You could add a c file with some unittests. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
▲ | cozzyd a day ago | parent | prev [-] | |||||||||||||||||||||||||||||||
Would be nice to know the code size e.g. on arm-none-eabi! | ||||||||||||||||||||||||||||||||
|