noob Q: array out-of-range

Duke Normandin dukeofperl at ml1.net
Fri May 28 16:41:33 PDT 2010


On Fri, 28 May 2010, bearophile wrote:

> Don:
> > The array initially has length of zero.
> > You need to write something like:
> > intArray = new int[3];
> > or
> > intArray.length = 3;
> > before putting anything into it.
>
> In some languages (Perl? Maybe Lua and PHP) arrays auto-create empty slots as needed, but in many languages you need to tell the language that you want some empty slots before you can put values inside them (this stricter behaviour can probably catch some bugs, and allows to produce faster programs).
>
> Another way to add items to a D dynamic array like intArray is to append them at the end, the language runtime takes care of creating new slots as needed:
>
> int[] intArray;
> intArray ~= 1;
> intArray ~= 2;
> intArray ~= 3;
>
> Bye,
> bearophile


@Don
@bearophile

Would you guys visit this URL real quick

http://compsci.ca/v3/viewtopic.php?t=9518

This is the site that I'm using to learn D. If you scroll down 3-4
screens full, you'll come to the "array" topic. Is this tutorial
outdated, wrong, or what, because it doesn't deem to sync with what
you two fine fellows are telling me about creating dynamic arrays in
the D-Language. TIA..
-- 
duke


More information about the Digitalmars-d-learn mailing list