From: Joseph Myers <joseph@codesourcery.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2] Support C2X printf %b, %B
Date: Wed, 10 Nov 2021 15:30:08 +0000 [thread overview]
Message-ID: <alpine.DEB.2.22.394.2111101526440.109771@digraph.polyomino.org.uk> (raw)
In-Reply-To: <87lf1w743t.fsf@oldenburg.str.redhat.com>
On Wed, 10 Nov 2021, Florian Weimer wrote:
> * Joseph Myers:
>
> > +@item @samp{%b}, @samp{%B}
> > +Print an integer as an unsigned binary number. @samp{%b} uses
> > +lower-case @samp{b} with the @samp{#} flag and @samp{%B} uses
> > +upper-case. @samp{%b} is an ISO C2X feature; @samp{%B} is an
> > +extension recommended by ISO C2X. @xref{Integer Conversions}, for
> > +details.
>
> The new tests do not contain any negative input numbers. Do they result
> in undefined behavior?
Negative input numbers result in undefined behavior when the specified
argument type is unsigned after the integer promotions, as with %b with no
length modifiers, since printf is specified to behave as if it uses va_arg
(with the promoted version of the specified argument type), and mixing
signed / unsigned types with va_arg is only valid when the value passed is
representable in both types.
Negative (int) input numbers are valid when the specified argument type is
int (promoted from a narrower unsigned type), and the tests do include
cases passing (int) 0x87654321 to %hb, %hB, %hhb, %hhB to test that.
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2021-11-10 15:30 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
2021-10-20 21:27 ` Joseph Myers
2021-11-10 9:27 ` Florian Weimer
2021-11-10 15:30 ` Joseph Myers [this message]
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=alpine.DEB.2.22.394.2111101526440.109771@digraph.polyomino.org.uk \
--to=joseph@codesourcery.com \
--cc=fweimer@redhat.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).