why no implicit convertion?
Tomek Sowiński
just at ask.me
Wed Nov 17 13:32:21 PST 2010
Matthias Pleh <sufu at alter.com> napisał(a):
> void foo(char[] a) {}
> void bar(char[][] b) {}
>
> int main(string[] args)
> {
> char[4] a;
> char[4][4] b;
> foo(a); // OK: implicit convertion
> bar(b); // Error: cannot implicitly convert
> // char[4u][4u] to char[][]
> }
>
> what is the reason for the different behaviour?
I *think* it's because multi-dim static arrays are a strip of contiguous
memory and no length information is held with the data, so if it was
converted to a dynamic array of arrays (who do hold their lengths), there
wouldn't be room for the lengths of the arrays.
> What's best to pass such multidimensional arrays?
Good question. Maybe new char[][](4) and point the inner arrays to the
chunks of the static array?
--
Tomek
More information about the Digitalmars-d-learn
mailing list