printf %b

Jonathan Nieder jrnieder@gmail.com
Sun Apr 26 00:54:07 GMT 2020


Hi!

Alejandro Colomar wrote:

> In my personal library, about a year ago, I wrote a function to register the
> ``b`` and ``B`` conversion specifiers using ``register_printf_specifier()``.
>
> They work the closest possible to ``o``, ``u``, ``x`` & ``X``:

You left out the key detail up here, that it writes a number in
binary. :)

The printf command line utility uses %b for something else: it prints
its argument as an expanded string, with backslashes interpolated.
For example, "foo\\tbar" becomes "foo	bar".  I think this is enough
reason not to use %b for something else in libc out of the box.  Of
course, particular programs registering a printf specifier are a
separate story.

That said, I don't want to discourage a potential glibc contributor.
For what it's worth, glibc's printf code is pretty messy and I would
be very happy to review a proposal for cleaning it up.

Thanks and hope that helps,
Jonathan


More information about the Libc-alpha mailing list