-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sprintf api integer enhancement #255
Comments
Thanks for the suggestion. I don't think it will benefit existing code, because it should already be using correct specifiers and switching to cppformat will have no effect other than introducing type safety. However, this may benefit the new code using cppformat's |
This is implemented in 8474a62. For example, the code fmt::printf("%d", std::numeric_limits<long long>::max()); prints Note that only narrowing conversions are disabled, sign and widening conversions still apply. |
Wonderful! I've been toying with a tentative implementation but yours is much more elegant. |
Hi, the sprintf api is unnecessarily converting integer arguments, leading to inexact values.
As an example, the format string "%d" converts its argument to plain int, even if it was long or long long.
While the original sprintf had no type information and must do that, cppformat is smarter and could do much better, for example preserving original type information.
So one could simply write "%d" or "%u" and have cppformat format the string according to the real argument size.
This would be very useful esp. on windows, where some types change size going from 32 to 64bit, but others not, leading to bugs difficult to find.
Obviously you also can use the format api, but then you need to rewrite existing code, while the sprintf api brings immediate benefits just by adding cppformat.
The text was updated successfully, but these errors were encountered: