From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 419BB3858D39 for ; Wed, 20 Oct 2021 21:00:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 419BB3858D39 Received: by mail-pl1-x634.google.com with SMTP id n11so17014460plf.4 for ; Wed, 20 Oct 2021 14:00:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EdYYiJmnHcdCZHrjjVdveGHYCKuziDFyNhi6mIglucM=; b=kq1vy09bcv7ZvdnhBNAOlk5I/+ZKrxGboqTfMmnweEn8UADVjP7VZAKPjMQWy9bXVg ibrHfMrjxVhCmbfigPvYSPEfUx23bke95bkus/9MqA6L7xaunC/NYwn31nowVsEyAYIH G2TjEK8KaYEXdOoUrJ6cgFPZTdwmdSri5bmrqmM9gviirUfI6Xrm/jNk7XI0NyGNZbBw sj4+HNryqCYBaLsBeQiWwLe/nj1R1cWEACdezVulhwz7Cn1pf2cMt8QGVM22SONaI2t7 WUU4HcFIQ+k19LvTUOLrMQVd40OvJOd90kQYXQGq1nDdOWZFhN2Cjg64cpPlS7FaHP6K 9Z4g== X-Gm-Message-State: AOAM5318rop+WbarVxsKXUtLZoQ9Tak6W63xUfLqYvpwnsOHuYEzr9SV MVRFdUScO+qvOllC904RpwuFKK+t+VMKBeu28YmKT5qI1c4= X-Google-Smtp-Source: ABdhPJxNB516rDoEaq1EEThP69QdPJ3aLdb66i5avPR/1syoVOIGdIRQEBRE73Gzg7HFjt6SpmVCnllpsjpT/c0rPz8= X-Received: by 2002:a17:902:e80c:b0:13f:1140:8ab2 with SMTP id u12-20020a170902e80c00b0013f11408ab2mr1364169plg.27.1634763649307; Wed, 20 Oct 2021 14:00:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Wed, 20 Oct 2021 14:00:13 -0700 Message-ID: Subject: Re: [PATCH v2] Support C2X printf %b, %B To: Joseph Myers Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3023.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Oct 2021 21:00:51 -0000 On Tue, Oct 12, 2021 at 5:38 PM Joseph Myers wrote: > > C2X adds a printf %b format (see > , 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 > , > 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.