Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1311803

Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form

From Rasmus Villemoes <linux@rasmusvillemoes.dk>
Newsgroups linux.kernel
Subject Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form
Date 2016-01-18 22:00 +0100
Message-ID <qSp47-5SG-19@gated-at.bofh.it> (permalink)
References <qQYz0-5b5-1@gated-at.bofh.it> <qQYz1-5b5-45@gated-at.bofh.it>
Organization D03

Show all headers | View raw


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

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 22:00 +0100

csiph-web