C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Array Index in Range-based For Loops

From: Ray Gardener <rgardener_at_[hidden]>
Date: Wed, 1 Mar 2023 12:47:58 -0800
Not gonna lie, if I see code exploiting integer overflow, I reject it. It
just smells hoity-toity. I like code to be dead obvious.

And as for assigning negative numbers to unsigned types, whatever happened
to type safety?

Ray


On Wed, Mar 1, 2023 at 11:21 AM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Wednesday, 1 March 2023 08:32:41 PST Ray Gardener via Std-Proposals
> wrote:
> > size_t can be assigned -1?
>
> Sure it can. Any out-of-range value is simply stored as if repeatedly
> adding
> or subtracting (SIZE_MAX + 1) until it is in range.
>
> so -1 is (SIZE_MAX + 1) - 1, which is SIZE_MAX.
>
> Some compilers will print a warning though (ICC was notable for the
> "change of
> sign" warning).
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel DCAI Cloud Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-03-01 20:48:10