C++ Logo


Advanced search

Re: [std-proposals] uint_nopro_fast32_t : Types in <cstdint> that don't promote

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 31 Mar 2023 13:21:36 +0100
On Fri, Mar 31, 2023 at 12:50 PM Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Could you explain, when the promotion would be detrimental?
> E.g.: unsigned overflow is defined behaviour (in comparison to signed overflow), but would it be useful, when you cannot predict the bitwidth?

Take the following:

    extern void Func(uint32_t);
    extern void Func(int64_t);

    void Monkey(uint32_t const arg)
        Func(arg + 5);

The overload called here is different depending on whether int is
32-Bit or 64-Bit.

Also let's say we allow it to roll over:

    uint32_t value = 5;

    auto monkey = value + 3;

    for ( ; ; monkey += 1024u*128u)
        // Do something

We get undefined behaviour here if 'monkey' is a signed 64-Bit integer
and we let it overflow.

Received on 2023-03-31 12:21:48