printf-like function.

Hi all,

I'm a printf-like function lover. I always found that better than doing something like out << "blabla : " << var1 << ", blabla" << etc.

Now, I use a lot of different platforms and to be portable, I'm supposed to use PRIxxx constants for portability. For me that half-breaks the readability of printf format.

What about a new set of functions that'll be specified slightly differently :

accepting %d for ANY number ? The compiler can modify the format litteral at compile time to fit what's needed for that platform, replacing %d by %hhd, %hd, %d, %ld, %lld, %hhu etc..
Replacing the litteral format at compile time prevents to modify the vararg mechanism.

Of course, if format is not litteral : no replacement !


2bis) some attributes could be passed on to this function so it'll know what to expect at runtime. I'm guessing modifying vararg mechanism to add attributes might be nearly impossible...

I'm interested of what would you all think about that ?


PS : we could do the same with %s that could accept char*, wchar_t*, char16_t*, char32_t*.

What about the fmt library? GitHub - fmtlib/fmt: A modern formatting library

A version of this was accepted to the c++20 spec, so in addition it'll be portable.

There is no contradictions.

fmt doesn't work with C. I'm also using C++ in freestanding env without STL on small devices with no dynamic memory allocation.

I still think that would be a nice addition, with no need to modify existing libraries. discusses the considerations for proposing extensions to clang - likely this might be best prototyped in a fork of clang (clang being on github, this should be fairly low-cost) & if a significant user base forms around it, and/or it’s the sort of thing you could propose for standardization in the relevant bodies (I guess getting a proposal for the C standard would be the place to start) then it might be good to discuss upstreaming it into clang proper