Re: Array operation doesn't check array bounds

2011-04-04 Thread Kai Meyer
On 04/03/2011 05:06 PM, Jonathan M Davis wrote: On 2011-04-03 04:10, simendsjo wrote: int[] a = [1,2,3]; int[4] b; assert(b == [0,0,0,0]); b = a[] * 3; // oops... a[] * 3 takes element outside a's bounds assert(b[$-1] == 0); // fails.. last element is *(a

Re: Array operation doesn't check array bounds

2011-04-03 Thread Jonathan M Davis
On 2011-04-03 04:10, simendsjo wrote: > int[] a = [1,2,3]; > > int[4] b; > assert(b == [0,0,0,0]); > b = a[] * 3; // oops... a[] * 3 takes element outside a's bounds > assert(b[$-1] == 0); // fails.. last element is *(a.ptr+3) * 3 Array bounds checking is done on cod

Re: Array operation doesn't check array bounds

2011-04-03 Thread bearophile
Simon: > No it doesn't. D is supposed to be systems programming language. > Unnecessary bounds checking would make array access too slow. D has already array bounds, even to access single items. Array operations are bulk, so they need only one bound test, then they perform many operations witho

Re: Array operation doesn't check array bounds

2011-04-03 Thread Simon
On 03/04/2011 12:39, simendsjo wrote: On 03.04.2011 13:32, Simon wrote: From the D spec: "A program may not rely on array bounds checking happening" Where in the spec are you finding this? Or are you talking in general, not just on array operations? D does bounds checking, so I don't see a

Re: Array operation doesn't check array bounds

2011-04-03 Thread Simon
On 03/04/2011 12:46, bearophile wrote: Simon: "A program may not rely on array bounds checking happening" Yet DMD has to perform them to help programmers. No it doesn't. D is supposed to be systems programming language. Unnecessary bounds checking would make array access too slow. Mind you

Re: Array operation doesn't check array bounds

2011-04-03 Thread bearophile
Simon: > "A program may not rely on array bounds checking happening" Yet DMD has to perform them to help programmers. I think this bug report is already in Bugzilla, but I'd like to be sure. Bye, bearophile

Re: Array operation doesn't check array bounds

2011-04-03 Thread simendsjo
On 03.04.2011 13:32, Simon wrote: From the D spec: "A program may not rely on array bounds checking happening" Where in the spec are you finding this? Or are you talking in general, not just on array operations? D does bounds checking, so I don't see a reason why it shouldn't do it on ar

Re: Array operation doesn't check array bounds

2011-04-03 Thread Simon
On 03/04/2011 12:10, simendsjo wrote: int[] a = [1,2,3]; int[4] b; assert(b == [0,0,0,0]); b = a[] * 3; // oops... a[] * 3 takes element outside a's bounds assert(b[$-1] == 0); // fails.. last element is *(a.ptr+3) * 3 From the D spec: "A program may no

Array operation doesn't check array bounds

2011-04-03 Thread simendsjo
int[] a = [1,2,3]; int[4] b; assert(b == [0,0,0,0]); b = a[] * 3; // oops... a[] * 3 takes element outside a's bounds assert(b[$-1] == 0); // fails.. last element is *(a.ptr+3) * 3