C++ Logo

sg16

Advanced search

Re: [isocpp-lib-ext] LEWG(I) (Bi)Weekly review - P2510R0: Formatting pointers

From: 'Mark de Wever' <koraq_at_[hidden]>
Date: Mon, 14 Feb 2022 20:46:46 +0100
On Sat, Feb 12, 2022 at 08:01:01PM +0200, Peter Dimov wrote:
> I have a small suggestion to make.
>
> My preferred output when printing numbers in hexadecimal is 0x05D4; that is,
> the base prefix is lowercase 0x, but the number itself uses uppercase A-F.
>
> This is not a problem for numbers because I can just omit the # and add the
> base prefix by hand, e.g. `0x{:04X}` instead of `{:#06X}`.
>
> But since # is implicit for pointers, this isn't (going to be) possible when using
> the P specifier.
>
> The most straightforward way I see to address that is to simply allow # for
> pointers, with the opposite meaning. That is, # when present will remove the
> base prefix, instead of adding it.

While writing the paper I've given the removal of the 0x prefix some
thought, but I wasn't too sure how useful it would be. So I didn't
investigate it a lot.

I'm not sure how intuitive the difference in meaning of # for integers
and pointers is. However the # already does something completely
different for floating-point types. So it's not just a difference in
behaviour between pointers and integers.

Currently # isn't allowed for pointers, so I don't see compatibility or
implementation issues.

I'll include it in the next version of the paper.

Cheers,
Mark

Received on 2022-02-14 19:46:50