Bounds check

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 23 08:14:46 PDT 2014


The following:

import std.stdio;

void main() {
   int[5] arg;
   arg[10] = 3;              // Compiler says (of course): Error: 
array index 10 is out of bounds arg[0 .. 5]
}

import std.stdio;

void main() {
   int[5] arg;
   foreach (i; 0..10) {
     arg[i] = i;
   }
}

Compiler says nothing, but we get a runtime error 'Range 
violation'.

Bug or design?



More information about the Digitalmars-d-learn mailing list