Array bound checks removal increasing importance

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 1 03:21:56 PDT 2014


Dmitry Olshansky:

> Who are those people that are not disabling bounds checks in 
> system language ? :)

If you show D code on Reddit and you show to compile with 
-noboundscheck you hear some people growl. I don't remember this 
happening much in past. So I think the attitude toward disabling 
bound checks is changing.

-----------

Once some more logic for bound checks removal is in D, it can 
even be added a @bounded expression attribute:

foreach (immutable i; 0 .. a.length)
     a[@bounded i]++;

@bounded {
     foreach (immutable i; 0 .. a.length)
         a[@bounded i]++;
}

The purpose of @bounded is just to give a compile-time error if 
the compiler is not able to remove one (or more if used with the 
{} syntax) array bound check.

Bye,
bearophile


More information about the Digitalmars-d mailing list