foreach counter now must be size_t ?

Norm norm.rowtree at gmail.com
Sat Feb 9 01:27:11 UTC 2019


On Saturday, 9 February 2019 at 00:15:41 UTC, Rubn wrote:
> On Friday, 8 February 2019 at 08:06:39 UTC, Nicholas Wilson 
> wrote:
>> On Thursday, 7 February 2019 at 23:02:14 UTC, Rubn wrote:
>>> [...]
>>
>> Its not a bug. In the case that a.length > int.max, the loop 
>> will not terminate and only print indices. If the loop was
>>
>>      for(int i = 0; i < a.length; ++i ) {
>>         writeln( a[i] );
>>      }
>>
>> it would still be @safe, but the program would crash because 
>> the index would (eventually) be OOB. If a.length > uint.max 
>> and the loop was
>>
>>      for(uint i = 0; i < a.length; ++i ) {
>>         writeln( a[i] );
>>      }
>>
>> then the loop fail to terminate, and it would still be @safe. 
>> All the above problems are avoided using size_t as the index.
>
> TIL infinite loop that freezes program isn't a bug.

It is a bug in your code, not the @safe.


More information about the Digitalmars-d mailing list