No bounds checking for dynamic arrays at compile time?
Walter Bright
newshound2 at digitalmars.com
Wed Dec 12 21:17:29 PST 2012
On 12/12/2012 9:09 PM, Marco Nembrini wrote:
> On Thursday, 13 December 2012 at 04:54:33 UTC, Walter Bright wrote:
>> On 12/12/2012 8:11 PM, Pacoup wrote:
>>> Static arrays throw out of bounds errors on compilation when there's a mismatch,
>>> but why not dynamic arrays?
>>
>> Because the length of dynamic arrays is unknown at compile time.
>
> That's true in general, but in this particular case you could see at compile
> time that the array is never resized and give a warning. Obvously as soon as
> there is one resizing somewhere with some run-time value you cannot do it anymore.
>
> I wonder if that would be useful?
You'd have to add data flow analysis to the front end, and you'd reap very
little useful error messages out of it.
Note that this example came from a tutorial, not real code.
More information about the Digitalmars-d
mailing list