29 ms·
It's a bit sad that the formatting API hasn't improved in C over the years. Take this code, for example: printf("Local number: %" PRIdPTR "\n\n", someIntPtr)
by vitaut 11y ago
It's a bit sad that the formatting API hasn't improved in C over the years. Take this code, for example:
printf("Local number: %" PRIdPTR "\n\n", someIntPtr);
which is quite unreadable to say the least. To address this issue I even wrote a small library (https://github.com/cppformat/cppformat https://github.com/cppformat/cppformat) that allows you to write something like this instead:
print("Local number: {}\n\n", someIntPtr);
It is written in C++ rather than C, because the latter doesn't have facilities (at least overloading is necessary) to implement such library.
- jhallenworld 11y agoThis is quite a nice library, I'll try it. Enhancement requests: - Option to insert commas or underscores every three digits (for decimal) or four digits (hex/binary/octal). - Option to print floating in engineering format (make exponent a multiple of 3). - Option to print floating but with a specific given exponent.
- vitaut 11y agoThanks for the suggestions. There has been some work to make formatting more customizable (https://github.com/cppformat/cppformat/issues/235 https://github.com/cppformat/cppformat/issues/235). This will enable extensions like the ones you suggest while keeping the library itself lean. Generally useful extensions like thousand separators can be added to the core library of course. They are actually on my TODO list.
- nly 11y agoThanks btw. I use your library and love it.
- nwmcsween 11y ago_Generic?