bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new modules *printf-gnu


From: Eric Blake
Subject: Re: new modules *printf-gnu
Date: Fri, 24 Mar 2023 11:11:38 -0500
User-agent: NeoMutt/20230322

On Fri, Mar 24, 2023 at 12:37:42PM +0100, Bruno Haible wrote:
> Eric Blake wrote in
> <https://lists.gnu.org/archive/html/bug-gnulib/2023-03/msg00060.html>:
> > C23 admits that %#B is not available for
> > portable use of outputting uppercase '0B...', you would have to
> > manually write 0B%b instead.  However, since glibc DOES support %B as
> > the uppercase counterpart to %b, should we add that in gnulib (but
> > this time under the auspices of *printf-gnu, rather than
> > *printf-posix)?
> 
> Nice idea. I was pondering what to do with the wording in ISO C23
>   "Implementations that did not use an uppercase B as their own
>    extension before are encouraged to implement it similar to
>    conversion specifier b as standardized above, with the
>    alternative form (#B) generating 0B as prefix for nonzero values."
> 
> "encouraged" - should we add it to the *printf-posix modules or not?
>

Ah, the fun of chasing a spec still in progress

> Your suggestion to put it under *printf-gnu, that being an extension
> of *printf-posix, makes perfect sense, since glibc implements %B
> since version 2.35. Implemented as follows.

The latest draft comments on C go a step further (warning, big document):
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3091.doc

Searching that for %B finds:
FR-217
Make %B optional
Accepted with comment: Wording from N 3072 section 15 with editorial corrections

so now go check N3072:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3072.htm#make-printf-format-specifier-b-optional

which states that the PRIBPTR in <inttype.h> is now a reliable witness
of whether %B has C23 semantics rather than other
implementation-defined semantics.

and glibc has updated their %B implementation accordingly:
https://sourceware.org/git/?p=glibc.git;a=commit;h=2d4728e60621

|  Update printf %b/%B C2x support
| 
| WG14 recently accepted two additions to the printf/scanf %b/%B
| support: there are now PRIb* and SCNb* macros in <inttypes.h>, and
| printf %B is now an optional feature defined in normative text,
| instead of recommended practice, with corresponding PRIB* macros that
| can also be used to test whether that optional feature is supported.
| See N3072 items 14 and 15 for details (those changes were accepted,
| some other changes in that paper weren't).
| 
| Add the corresponding PRI* macros to glibc and update one place in the
| manual referring to %B as recommended.  (SCNb* should naturally be
| added at the same time as the corresponding scanf %b support.)

Since %B is optional (but now MUST have a reliable PRIBPTR witness
macro), I could see still keeping it in only the gnu-*printf variants.
Or we can just state that we are going to blindly define PRIBPTR in
inttypes.h if the posix-*printf variants are in use.  Either way, you
probably want to work on followup patches that take PRIBPTR into
account.

Thanks for all your work on this, by the way!

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]