several questions

torhu no at spam.invalid
Fri Feb 15 15:40:59 PST 2008


Saaa wrote:
> And does this mean that static arrays are not passed by reference and should 
> I use:
> void func(ref array.ptr)
> ,because otherwise the whole array is passed (copied) ? (which sound slow:)

Static arrays as passed as the address of the first element.  So yes, 
that's 'by reference'.


These two are implemented in the exact same way:

void func(int[3] array);
void func(int* ptr_to_some_ints);

// used like:
int[3] array = [1, 2, 3];
func(array);
func(array.ptr);


The important difference is that inside the second function, the 
compiler does not care about how many elements 'array' contains, and you 
don't get automatic array bounds checking.


More information about the Digitalmars-d-learn mailing list