C++ Logo

std-proposals

Advanced search

Re: [std-proposals] New printf/scanf modifiers

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 31 Jan 2023 13:47:48 -0500
On Tue, Jan 31, 2023 at 1:41 PM Lee Shallis via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> since hh, h, etc are unused I decided to use them in my own
> implementation (separate name to standard printf) and just now thought
> to suggest them.
>
> hh = char8_t (In my equivalent typedef I chose to default to wchar_t
> when char is too small in a non standards compliant implementation)
> h = char16_t
> ll = char32_t (since l is reserved for wchar_t and the lack thereof for char)
> t = tchar_t (TCHAR on windows and char on linux)
> j = char32_t (since that's currently the biggest there is, we never
> know if we'll ever need bigger, for example space alien character sets
> - assuming they exist)
>
> I also used v as a modifier for intptr_t/uintptr_t, took it from void*
>
> Also I think .* should be used to indicate the max characters to scan
> for any string, for example
>
> #define LENG 7
> char name[LENG+1] = "";
> scanf("%.*s",LENG,name);
>
> With the input of "Hello world!" would give "Hello w"

Why do we want to improve type-unsafe tools like `printf` when we have
type-safe tools like `std::format`? We don't quite have a scanf
equivalent yet, but it'd be better to work on that.

Received on 2023-01-31 18:48:26