From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by sourceware.org (Postfix) with ESMTPS id 34F56386F021 for ; Sun, 26 Apr 2020 00:54:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 34F56386F021 Received: by mail-pj1-x102f.google.com with SMTP id fu13so5103282pjb.5 for ; Sat, 25 Apr 2020 17:54:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=xFXygFG6c7UzptqatI3EVYBBqcRQVYl6/445N8Q9oIE=; b=LnpTF3r3dzqWwXW4q/4xS6aQ235TY29G3zf3yWoVFy3HRjKnJPXvGiuazxQ5aO56Hp F+Muxjan/GQEQ0AYXfIuXpBB/baVf3lrQpbPoYdY9lGAomubn0GjHCmRCz3ja9MgDDME VLvsW8+63hh6HwPLbmEfHLwIFRM0ZxrncGMO20XcdYXgpSOhzTntYzZmpLEtOHElUi+y K+Lz7c4STmFe6wJ9dP3dkrpYE4jrWJkXj3/NFizkTHzNnYTmxPCeFQNxVAsd/Q0tZGVQ laDbZJBp/5vHHC1fOM6tkttoO7gHl/gotLATl1gAnfUoN/f40uZ6V7ymaIg5D9Yw4bGz j0EA== X-Gm-Message-State: AGi0PubCTtQikIHbzlthi3eZZ9Cr/iJtiQ5k4c/i4K8cXTPxPyKVUCri JChTdEkd9tRyjRodXjicKFseG3Aa X-Google-Smtp-Source: APiQypIE3wvkJx88087ylgs1Tlb3QFToodZNQsnFfcoew0ukOEeLZZ2soz88r9MLim5MVSkrMcNXOg== X-Received: by 2002:a17:902:7c04:: with SMTP id x4mr14583775pll.238.1587862451239; Sat, 25 Apr 2020 17:54:11 -0700 (PDT) Received: from gmail.com (174.247.233.35.bc.googleusercontent.com. [35.233.247.174]) by smtp.gmail.com with ESMTPSA id b1sm8787894pfa.202.2020.04.25.17.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2020 17:54:10 -0700 (PDT) Date: Sat, 25 Apr 2020 17:54:07 -0700 From: Jonathan Nieder To: Alejandro Colomar Cc: libc-alpha@sourceware.org Subject: Re: printf %b Message-ID: <20200426005407.GE877@gmail.com> References: <1137ece3-27fb-0ca8-22df-dcc69077f354@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1137ece3-27fb-0ca8-22df-dcc69077f354@gmail.com> X-Spam-Status: No, score=-3.0 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.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 00:54:13 -0000 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. :) 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 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. Thanks and hope that helps, Jonathan