format icon indicating copy to clipboard operation
format copied to clipboard

Enhancement: format (u)int8 types correctly to number, if formatted with %d, &i, %u

Open s-martin opened this issue 7 years ago • 2 comments

If I try to format a (u)int8 number, Boost.Format considers this as (unsigned) char, even if I use %d, %i or %u.

This is a known and rather old issue.

The workaround is to cast the number to (u)int32, before formatting.

Nevertheless the current behavior leads to very subtle bugs, because the developer has to check the type of the number to be printed very carefully.

Plain printf handles (u)int8 numbers in combination with %d, %i or %u correctly.

Boost version: 1.68 (32bit) Compiler: MSVC 15.8

s-martin avatar Oct 05 '18 15:10 s-martin

Just faced with the same issue trying to format GUID to its string representation. I use %02X to format the last bytes, but unexpectedly it was shown as non-US-ASCII character =(.

It there any plans to fix this? cc @jeking3

k15tfu avatar Dec 03 '19 20:12 k15tfu

I don't think this is an enhancement. This just bit me and imho it's a plain bug: i specifically ask for some kind of numeric formatting and it simply doesnt. If I specify '%x' and the argument is a string it should just throw.

maddanio avatar Jun 15 '22 15:06 maddanio