[cfe-dev] printf-like function.

JF Knudsen via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 19 23:53:12 PDT 2020


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 !

OR

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 ?

Thanks.


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



More information about the cfe-dev mailing list