From 2d88df541132f09454d947c498103aa7be76b652 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 19 Jun 2023 19:40:34 +0000 Subject: 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 . 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. --- stdlib/inttypes.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'stdlib/inttypes.h') diff --git a/stdlib/inttypes.h b/stdlib/inttypes.h index 8f0fa8ab9f..42ecf681cc 100644 --- a/stdlib/inttypes.h +++ b/stdlib/inttypes.h @@ -302,6 +302,28 @@ typedef wchar_t __gwchar_t; # define SCNxPTR __PRIPTR_PREFIX "x" +/* Binary notation. */ +# if __GLIBC_USE (ISOC2X) +# define SCNb8 "hhb" +# define SCNb16 "hb" +# define SCNb32 "b" +# define SCNb64 __PRI64_PREFIX "b" + +# define SCNbLEAST8 "hhb" +# define SCNbLEAST16 "hb" +# define SCNbLEAST32 "b" +# define SCNbLEAST64 __PRI64_PREFIX "b" + +# define SCNbFAST8 "hhb" +# define SCNbFAST16 __PRIPTR_PREFIX "b" +# define SCNbFAST32 __PRIPTR_PREFIX "b" +# define SCNbFAST64 __PRI64_PREFIX "b" + +# define SCNbMAX __PRI64_PREFIX "b" +# define SCNbPTR __PRIPTR_PREFIX "b" +# endif + + __BEGIN_DECLS #if __WORDSIZE == 64 -- cgit 1.4.1