lkml.org 
[lkml]   [2016]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form
Date
On Thu, Jan 14 2016, Andy Shevchenko <andriy.shevchenko@linux.intel.com> 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].

Rasmus

\
 
 \ /
  Last update: 2016-01-18 22:21    [W:0.038 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site