foreach counter now must be size_t ?

Rubn where at is.this
Tue Feb 5 23:10:10 UTC 2019


On Tuesday, 5 February 2019 at 23:04:16 UTC, Walter Bright wrote:
> On 2/5/2019 1:14 PM, Rubn wrote:
>> WHAT. WHAT. Where do you see an assignment from size_t to int 
>> here?
>> 
>> int[] arr = someRandomArray();
>> for( int i = 0; i < arr.length; ++i ) {
>>     dg( i, arr[i] );
>> }
>> 
>> ???
>
> The ++i overflows and the loop never terminates.

Just as it is safe.

@safe void foo(int[] a) {
     for(int i = 0; i < a.length; ++i ) {
        writeln( i );
     }
}


More information about the Digitalmars-d mailing list