noob Q: array out-of-range

Steven Schveighoffer schveiguy at yahoo.com
Fri May 28 21:43:19 PDT 2010


On Fri, 28 May 2010 22:42:32 -0400, Duke Normandin <dukeofperl at ml1.net>  
wrote:

> On Sat, 29 May 2010, Simen kjaeraas wrote:
>
>> Duke Normandin <dukeofperl at ml1.net> wrote:
>>
>> > So these two paragraphs in the tutorial are flat out wrong?
>>
>> Absolutely.
>
> Then I'm done with _that_ site - can't trust it!
>
> Any chance that you could suggest a good beginner's D tutorial?
>

It's quite possible that the example code *worked* at some very early  
version of the D compiler.

Nowadays, all arrays are initialized with null as the pointer,  
guaranteeing that the first time you access array[0], it will segfault.   
So with the current compilers, that code is *guaranteed* to not work.

I speak not from experience, ever since I've started using D it always  
initializes arrays to null.  I just can't imagine that someone would have  
written such a tutorial without having some experience with D, and without  
ever having compiled the code.  So my logical conclusion is that either 1)  
at some point, that code did work, 2) the author was so convinced of his D  
mastery that he didn't bother to try any of his examples, or 3) the page  
is a blatant attempt to make users not like D.

I find 2 unlikely since he specifically mentions how you don't have to  
initialize arrays.

I wonder if someone recalls the feature set of the dmd compiler from July,  
2005.

-Steve


More information about the Digitalmars-d-learn mailing list