Dynamic arrays

jmh530 via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Aug 31 15:03:04 PDT 2015


On Monday, 31 August 2015 at 21:09:02 UTC, Minas Mina wrote:
> Constructive criticism is welcome.

In the "define a dynamic array" section, I often find myself 
writing
int[] numbers;
numbers.length = 3;
Instead of
int[] numbers = new int[3];
I understand that this fits with the resizing section later a bit 
better, but it's just how I typically do it.

You might show some examples of functions where you can pass 
dynamic arrays, but not static arrays.

In general, I find myself very easily getting mixed up by the 
syntax of the static vs. dynamic arrays. For instance, compare
int[] x = new int[3];
int[3] y = new int[3];
auto z = new int[3];
x and y are obviously dynamic and static arrays, respectively. 
However, my initial guess on z is that is like y, a static array 
on the heap. But that is wrong. It's actually like x. Easy to get 
confused.


More information about the Digitalmars-d-announce mailing list