www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: static arrays becoming value types

Sorry for the late answer, I have missed your answer until now.


 Here's a way around that:  To pass a static array by reference to a templated
 function that was written with generic ranges in mind, just slice it to make
it a
 dynamic array:
 float[3] foo;
 pragma(msg, typeof(foo[]).stringof);  // float[]

Or you can also pass a pointer to the first item of the fixed-size array: bar(foo.ptr); This change (static arrays becoming value types) will make D less similar to C, so porting C code to D will be less easy (because if in the original C code an array is passed, now the code is slower, and changes to the array can't be seen outside of the function). I think as time passes, D may become less and less compatible with C (and this is has both advantages and disadvantages). A possible solution is to add a new kind of modules to D, the C-like ones, where semantics is kept closer to C (and where switch() has fall-through, etc). No one elase has commented that silly idea of the .ref I have shown. Maybe it's a wrong idea. Bye, bearophile
Oct 24 2009