From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 839D4386F021 for ; Sun, 26 Apr 2020 02:29:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 839D4386F021 Received: by mail-wm1-x32d.google.com with SMTP id y24so16376437wma.4 for ; Sat, 25 Apr 2020 19:29:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:cc:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OSAEGTksJU63Cj+bXlsf0/gLcIpwrjK0Jc4cfMXnHZ0=; b=aXf8m/7iOp+HoIbSnpKNKwK9sK9Gq08xiHtjrShnZobELBkOxw4EozAbeNbWHaXlpn uEg86pcbsv6Zriy/716r0HwpHU0cyc5SmAVZKsewM+gA+tVGXRikZs0bXwXAol/dMG7l /hGADdHQT2rqHHklrD+0RUfX/+mLMnIQqCIBtqJmCLWNZAEMCik9oT4oIdTSWtp5xe/z SQrvvVqkR60HS79GaJ0DL/IvSEBXxHy47COmNDVYdphBU4a2/WWTqiuK757WFmjdjSgt E/IAbChjocVz0ETUshid8mBhp+IN0qDWzJh3tRYaqNGiXekcnYhS1xEUktZV6f/qgh4s hYKQ== X-Gm-Message-State: AGi0PuakCqlU5HPtRThKYh35EKCDfO6WANjSMJ101W5d1ucJ18q1Rkx8 0q5hW2lzuG1kLW5tID8kqrdj8+gL X-Google-Smtp-Source: APiQypKgblIP1SmlIphg9kLFRGRzdmBUwm/xjlMZoF4UwY8b/GXgJThFMa+Ec2qRzmizdnjtcWor7w== X-Received: by 2002:a1c:9816:: with SMTP id a22mr17971315wme.125.1587868181417; Sat, 25 Apr 2020 19:29:41 -0700 (PDT) Received: from [192.168.1.131] ([93.176.137.11]) by smtp.gmail.com with ESMTPSA id n6sm16363339wrs.81.2020.04.25.19.29.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Apr 2020 19:29:40 -0700 (PDT) Subject: Re: printf %b To: Jonathan Nieder References: <1137ece3-27fb-0ca8-22df-dcc69077f354@gmail.com> <20200426005407.GE877@gmail.com> From: Alejandro Colomar Cc: libc-alpha@sourceware.org Message-ID: <6e163d3e-fc4f-7a87-6168-890c21a00dde@gmail.com> Date: Sun, 26 Apr 2020 04:29:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200426005407.GE877@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sun, 26 Apr 2020 02:29:43 -0000 On 4/26/20 2:54 AM, Jonathan Nieder wrote: > Hi! > > Alejandro Colomar wrote: > >> In my personal library, about a year ago, I wrote a function to register the >> ``b`` and ``B`` conversion specifiers using ``register_printf_specifier()``. >> >> They work the closest possible to ``o``, ``u``, ``x`` & ``X``: > > You left out the key detail up here, that it writes a number in > binary. :) Yup, I forgot the main point :) > > The printf command line utility uses %b for something else: it prints > its argument as an expanded string, with backslashes interpolated. > For example, "foo\\tbar" becomes "foo bar". I think this is enough > reason not to use %b for something else in libc out of the box. Of Hmmm. Good point. Maybe, given that binary doesn't have letters such as hex does, we don't need both ``%b`` and ``%B``. We could have just ``%B`` (if it isn't already taken by some other thing) and use it for binary. > course, particular programs registering a printf specifier are a > separate story. > > That said, I don't want to discourage a potential glibc contributor. > For what it's worth, glibc's printf code is pretty messy and I would > be very happy to review a proposal for cleaning it up. I can try. I do agree that it is messy; maybe too much for me to understand it. > > Thanks and hope that helps, > Jonathan Thank you very much. Alex.