Bounds check

2014-05-23 Thread Chris via Digitalmars-d-learn
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

Re: Bounds check

2014-05-23 Thread Meta via Digitalmars-d-learn
On Friday, 23 May 2014 at 15:14:47 UTC, Chris wrote: 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;

Re: Bounds check

2014-05-23 Thread John Colvin via Digitalmars-d-learn
On Friday, 23 May 2014 at 15:14:47 UTC, Chris wrote: 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;

Re: Bounds check

2014-05-23 Thread bearophile via Digitalmars-d-learn
Chris: 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

user defined no bounds check

2012-08-20 Thread monarch_dodra
There is a way to prevent bounds checking of array accesses when compiling. I was wondering if there was a way to have a user defined range apply the same scheme? I'd suppose using a version? I'm not very fluent with this yet...

Re: user defined no bounds check

2012-08-20 Thread Jonathan M Davis
On Monday, August 20, 2012 10:43:43 monarch_dodra wrote: There is a way to prevent bounds checking of array accesses when compiling. I was wondering if there was a way to have a user defined range apply the same scheme? I'd suppose using a version? I'm not very fluent with this yet... I

Re: user defined no bounds check

2012-08-20 Thread monarch_dodra
On Monday, 20 August 2012 at 09:10:47 UTC, Jonathan M Davis wrote: On Monday, August 20, 2012 10:43:43 monarch_dodra wrote: There is a way to prevent bounds checking of array accesses when compiling. I was wondering if there was a way to have a user defined range apply the same scheme? I'd

Re: user defined no bounds check

2012-08-20 Thread Jonathan M Davis
On Monday, August 20, 2012 11:45:23 monarch_dodra wrote: On Monday, 20 August 2012 at 09:10:47 UTC, Jonathan M Davis wrote: On Monday, August 20, 2012 10:43:43 monarch_dodra wrote: There is a way to prevent bounds checking of array accesses when compiling. I was wondering if there was a

Re: user defined no bounds check

2012-08-20 Thread monarch_dodra
On Monday, 20 August 2012 at 09:58:54 UTC, Jonathan M Davis wrote: I'm not sure that it was ever even considered that the programmer might want to do something special with them. assert is affected by -release, and - noboundscheck was added later for extra control. They had nothing to do

Re: user defined no bounds check

2012-08-20 Thread Jonathan M Davis
On Monday, August 20, 2012 12:44:40 monarch_dodra wrote: Andrei says something in his book along the lines of If a built in can do it, so should a user defined type (don't have the quote here though, sorry). So basically, if a built in array can conditionally control bounds checking, why can't

Re: user defined no bounds check

2012-08-20 Thread monarch_dodra
On Monday, 20 August 2012 at 15:42:50 UTC, Jonathan M Davis wrote: On Monday, August 20, 2012 12:44:40 monarch_dodra wrote: Except that generally assert does the job just fine. The only reason that - noboundscheck is any different really is the fact that bounds checking is left on in @safe