Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form
From: Rasmus Villemoes
Date: Mon Jan 18 2016 - 15:58:19 EST
On Thu, Jan 14 2016, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> Introduce a new extension for printing given unsigned long long value in
> human-readable form with automatically choosen IEC binary prefix. The value is
> passed by reference.
I don't like this, and don't find it particularly useful. There's also
the problem Joe mentions with types; inevitably, someone wants to pass a
size_t or an unsigned int or whatnot, and allowing that gets ugly, as is
forcing the caller to copy the value to a temp u64.
If you really want this, I think it would be much better to introduce a
helper which takes a user-supplied (typically small stack) buffer,
formats into that, and maybe for convenience returns that buffer (so it
can be passed directly to a %s). That's a lot more flexible, and avoids
the annoying type issue since the user's value just gets passed directly
(and thus auto-promoted to u64) to the helper.
The %pX space is also rapidly diminishing, so we should think twice
before introducing yet another rarely used extension.
In any case, I had to read the implementation to figure out that the
prefix chosen is the largest for which the printed value is exactly what
was passed in. Please make that more explicit. [It also means that the
printed string isn't necessarily human readable at all, as your test
value 1097364144125 shows].