C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Tue, 31 Jan 2023 15:15:25 -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)
>

Many of your suggestions are already standard C and C++. For example:
    printf("%hhd", sc); // signed char
    printf("%hd", ss); // signed short
    printf("%hu", us); // unsigned short
    printf("%td", d); // ptrdiff_t
    printf("%zu", z); // size_t
    printf("%jd", imax); // intmax_t

See the full list by doing `man printf`, or checking cppreference.
https://man.openbsd.org/printf.3
https://en.cppreference.com/w/cpp/io/c/fprintf

HTH,
Arthur

Received on 2023-01-31 20:15:38