printf-like function.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

printf-like function.

suyash singh via cfe-dev
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*.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: printf-like function.

suyash singh via cfe-dev
What about the fmt library? https://github.com/fmtlib/fmt

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

-----Original Message-----
From: cfe-dev <[hidden email]> On Behalf Of JF Knudsen via cfe-dev
Sent: Thursday, March 19, 2020 11:53 PM
To: [hidden email]
Subject: [cfe-dev] 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 !

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*.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: printf-like function.

suyash singh via cfe-dev
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.

On 20.03.20 17:06, Keane, Erich via cfe-dev wrote:

> What about the fmt library? https://github.com/fmtlib/fmt
>
> A version of this was accepted to the c++20 spec, so in addition it'll be portable.
>
> -----Original Message-----
> From: cfe-dev <[hidden email]> On Behalf Of JF Knudsen via cfe-dev
> Sent: Thursday, March 19, 2020 11:53 PM
> To: [hidden email]
> Subject: [cfe-dev] 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 !
>
> 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*.
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: printf-like function.

suyash singh via cfe-dev
https://clang.llvm.org/get_involved.html 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

On Fri, Mar 20, 2020 at 7:15 AM JF Knudsen via cfe-dev <[hidden email]> wrote:
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.

On 20.03.20 17:06, Keane, Erich via cfe-dev wrote:
> What about the fmt library? https://github.com/fmtlib/fmt
>
> A version of this was accepted to the c++20 spec, so in addition it'll be portable.
>
> -----Original Message-----
> From: cfe-dev <[hidden email]> On Behalf Of JF Knudsen via cfe-dev
> Sent: Thursday, March 19, 2020 11:53 PM
> To: [hidden email]
> Subject: [cfe-dev] 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 !
>
> 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*.
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev