May 02, 2004 Assoc. array as 'in' function parameter | ||||
---|---|---|---|---|
| ||||
[code] void foo(int[int] foobar) { foobar[1] = 1; } void main() { int[int] bar; foo(bar); printf("%d", bar.length); } [/code] If assoc. array 'bar' is not initialized, then: If 'foobar' is 'in', program outputs '0', i.e. all changes in array are discarded. If 'foobar' is 'out' or 'inout', program outputs '1'. If 'bar' is initialized (it can be empty or not), with 'in', 'inout', 'out' program output is '1'. |
May 24, 2004 Re: Assoc. array as 'in' function parameter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | It's a similar issue as with dynamic arrays. Inserting elements into one involves reallocating the storage for it, and since 'in' uses value semantics, it's working on a copy, not the original. "Sark7" <sark7@mail333.com> wrote in message news:opr7dyu6bkut8jae@news.digitalmars.com... > [code] > void foo(int[int] foobar) { > foobar[1] = 1; > } > void main() { > int[int] bar; > foo(bar); > printf("%d", bar.length); > } > [/code] > > If assoc. array 'bar' is not initialized, then: > If 'foobar' is 'in', program outputs '0', i.e. all changes in array are > discarded. > If 'foobar' is 'out' or 'inout', program outputs '1'. > > If 'bar' is initialized (it can be empty or not), with 'in', 'inout', > 'out' program output is '1'. |
Copyright © 1999-2021 by the D Language Foundation