aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2023-06-19 19:40:34 +0000
committerJoseph Myers <joseph@codesourcery.com>2023-06-19 19:40:34 +0000
commit2d88df541132f09454d947c498103aa7be76b652 (patch)
tree93e7cc592019cda92c8edb9a30ac4f1c2757386c /manual
parent5f83b2674e42cd74257731b281f66d0442bf045f (diff)
downloadglibc-2d88df541132f09454d947c498103aa7be76b652.zip
glibc-2d88df541132f09454d947c498103aa7be76b652.tar.gz
glibc-2d88df541132f09454d947c498103aa7be76b652.tar.bz2
C2x scanf %b support
ISO C2x defines scanf %b for input of binary integers (with an optional 0b or 0B prefix). Implement such support, along with the corresponding SCNb* macros in <inttypes.h>. Unlike the support for binary integers with 0b or 0B prefix with scanf %i, this is supported in all versions of scanf (independent of the standards mode used for compilation), because there are no backwards compatibility concerns (%b wasn't previously a supported format) the way there were for %i. Tested for x86_64 and x86.
Diffstat (limited to 'manual')
-rw-r--r--manual/stdio.texi12
1 files changed, 9 insertions, 3 deletions
diff --git a/manual/stdio.texi b/manual/stdio.texi
index a981e65..9cf6224 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -3545,6 +3545,10 @@ Matches an optionally signed integer in any of the formats that the C
language defines for specifying an integer constant. @xref{Numeric
Input Conversions}.
+@item @samp{%b}
+Matches an unsigned integer written in binary radix. This is an ISO
+C2X feature. @xref{Numeric Input Conversions}.
+
@item @samp{%o}
Matches an unsigned integer written in octal radix.
@xref{Numeric Input Conversions}.
@@ -3652,11 +3656,13 @@ For example, any of the strings @samp{10}, @samp{0xa}, or @samp{012}
could be read in as integers under the @samp{%i} conversion. Each of
these specifies a number with decimal value @code{10}.
-The @samp{%o}, @samp{%u}, and @samp{%x} conversions match unsigned
-integers in octal, decimal, and hexadecimal radices, respectively. The
+The @samp{%b}, @samp{%o}, @samp{%u}, and @samp{%x} conversions match unsigned
+integers in binary, octal, decimal, and hexadecimal radices, respectively. The
syntax that is recognized is the same as that for the @code{strtoul}
function (@pxref{Parsing of Integers}) with the appropriate value
-(@code{8}, @code{10}, or @code{16}) for the @var{base} argument.
+(@code{2}, @code{8}, @code{10}, or @code{16}) for the @var{base}
+argument. The @samp{%b} conversion accepts an optional leading
+@samp{0b} or @samp{0B} in all standards modes.
The @samp{%X} conversion is identical to the @samp{%x} conversion. They
both permit either uppercase or lowercase letters to be used as digits.