No bounds checking for dynamic arrays at compile time?
Walter Bright
newshound2 at digitalmars.com
Thu Dec 13 01:54:40 PST 2012
On 12/13/2012 1:38 AM, bearophile wrote:
> To spot at compile-time situations like:
>
>
> void main() {
> int[5] x;
> x[$] = 1;
> enum size_t n = 2;
> x[$ + n] = 2;
> }
The compiler does that already.
> void main() {
> int[] x = new int[5];
> x[$] = 1; // easy
> x[x.length] = 1; // idem
> enum size_t n = 2;
> x[$ + n] = 2; // not too much hard if n is unsigned
> x[x.length + n] = 2; // idem
> }
I just don't see the point in adding flow analysis for that, and it'll ding you
at runtime anyway. There are a lot more interesting things that flow analysis
can do.
More information about the Digitalmars-d
mailing list