public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2] Support C2X printf %b, %B
Date: Wed, 20 Oct 2021 14:00:13 -0700	[thread overview]
Message-ID: <CAMe9rOouhOJW-0jq7V6JTgGHqqPphm=5K44VKgd6ONQM2apiFA@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2110130037060.1580815@digraph.polyomino.org.uk>

On Tue, Oct 12, 2021 at 5:38 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> C2X adds a printf %b format (see
> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2630.pdf>, accepted
> for C2X), for outputting integers in binary.  It also has recommended
> practice for a corresponding %B format (like %b, but %#B starts the
> output with 0B instead of 0b).  Add support for these formats to
> glibc.
>
> One existing test uses %b as an example of an unknown format, to test
> how glibc printf handles unknown formats; change that to %v.  Use of
> %b and %B as user-registered format specifiers continues to work (and
> we already have a test that covers that, tst-printfsz.c).
>
> Note that C2X also has scanf %b support, plus support for binary
> constants starting 0b in strtol (base 0 and 2) and scanf %i (strtol
> base 0 and scanf %i coming from a previous paper that added binary
> integer literals).  I intend to implement those features in a separate
> patch or patches; as discussed in the thread starting at
> <https://sourceware.org/pipermail/libc-alpha/2020-December/120414.html>,
> they will be more complicated because they involve adding extra public
> symbols to ensure compatibility with existing code that might not
> expect 0b constants to be handled by strtol base 0 and 2 and scanf %i,
> whereas simply adding a new format specifier poses no such
> compatibility concerns.
>
> Note that the actual conversion from integer to string uses existing
> code in _itoa.c.  That code has special cases for bases 8, 10 and 16,
> probably so that the compiler can optimize division by an integer
> constant in the code for those bases.  If desired such special cases
> could easily be added for base 2 as well, but that would be an
> optimization, not actually needed for these printf formats to work.
>
> Tested for x86_64 and x86.  Also tested with build-many-glibcs.py for
> aarch64-linux-gnu with GCC mainline to make sure that the test does
> indeed build with GCC 12 (where format checking warnings are enabled
> for most of the test).
>

Binaries using such C2X specifiers should have a dependency on
the glibc version which supports them.  Ideally this dependency
should be added only when C2X specifiers are used.

-- 
H.J.

  parent reply	other threads:[~2021-10-20 21:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 23:15 Joseph Myers
2021-10-13  0:37 ` [PATCH v2] " Joseph Myers
2021-10-18 16:05   ` Ping " Joseph Myers
2021-10-26 20:49     ` Ping^2 " Joseph Myers
2021-11-01 16:56       ` Ping^3 " Joseph Myers
2021-11-08 15:03         ` Ping^4 " Joseph Myers
2021-11-08 15:38           ` Paul Zimmermann
2021-10-20 21:00   ` H.J. Lu [this message]
2021-10-20 21:27     ` Joseph Myers
2021-11-10  9:27   ` Florian Weimer
2021-11-10 15:30     ` Joseph Myers
2021-11-10 15:37       ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOouhOJW-0jq7V6JTgGHqqPphm=5K44VKgd6ONQM2apiFA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).