array questions
yes
yes at no.com
Sun Jan 11 16:01:53 PST 2009
>
> > Hello again
> >
> > is it possible to make a dynamic array less dynamic?
> >
> > int[][] array;
> >
> > array[0].length = 10; //has to be set at runtime
>
> Um, if that's your code, everything should crash at this point (or throw
> in debug mode): array is null, that is, empty, so there is no array[0].
>
> You should array.length = 10; first. Then you'll get an array of 10
well, at least to 2. my fault.
> empty arrays of int, and will be able to set their lengths separately:
>
> array[0].length = 10; // OK
> assert(array[1].length == 0); // OK
>
> If you want to set up quickly you can write
>
> int[][] array = new int[][](10, 10);
thank you, that will make all the element to be at least a certain size.
>
> This will give you a sort of square matrix, bit internally it will be an
> array of arrays nevertheless.
>
> > also, can this be done?
> >
> > int size;
> > size = 10; //runtime
> > void function( int[size][] array){}
>
> No, static arrays are static, i.e. compile time.
I meant it to be an dynamic array argument, but that the function wouldn't need to check the size of all the elements itself.
More information about the Digitalmars-d-learn
mailing list