array questions

Daniel Keep daniel.keep.lists at gmail.com
Sun Jan 11 16:08:26 PST 2009



yes wrote:
>>> [snip]
>>> 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.

Dynamic arrays do not have a fixed size, thus code needs to check the 
number of elements when it uses them.

Static arrays have a fixed size, but that size MUST be fixed at compile 
time.

You can convert static arrays into dynamic arrays, but not the other way 
around (at least, not without copying the contents).

When you compile with the -release flag, it disables range checking. 
You can also avoid it by going via pointers, but that's just asking for 
trouble.

   -- Daniel


More information about the Digitalmars-d-learn mailing list