C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 01 Mar 2023 11:21:00 -0800
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

Received on 2023-03-01 19:21:03