Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
April 03, 2003 arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
void foo(out char[32] test) { } DMD gives the error that char[32] can't be an out parameter. I realize arrays are passed by reference implicitly. I was after more of the behavior you get when you return an array, but without the temporary. char[32] foo() { char[32] result; return result; } Oh well. I think it's by design. Sean |
April 03, 2003 Re: arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Hmm. Then, how does one modify an array in D without copying (besides wrapping it in a class)? Luna Kid "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:b6h0ql$2tva$1@digitaldaemon.com... > void foo(out char[32] test) > { > } > > DMD gives the error that char[32] can't be an out parameter. > > I realize arrays are passed by reference implicitly. I was after more of the behavior you get when you return an array, but without the temporary. > > char[32] foo() > { > char[32] result; > return result; > } > > Oh well. I think it's by design. > > Sean > > |
April 03, 2003 Re: arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luna Kid | "Luna Kid" <lunakid@neuropolis.org> wrote in message news:b6h9nv$21k$1@digitaldaemon.com... > Hmm. Then, how does one modify an array in D > without copying (besides wrapping it in a class)? arrays are not arrays in the java/C sense, they are slices int[] foo = new int[40]; equiv to struct array { T * start; int length; } foo.start = (int*)calloc( 40, sizeof(int) ); foo.length = 40; int func( int[] parm ) ... is equiv to the C int func( struct array param ) ... so you get the start and length, which allows modifications to data but not length (just like delphi open arrays). arrays can be inout they can not be out I assume because that would cause implict allocations you can get out without copying with char[] func() { char[] foo = new char[32]; return foo[0..32]; } a work of warning do not be tempted to write char[] func( ){ char [32] foo; return foo[0..32]; } will return a slice alllowing access to the stack :) > > Luna Kid > > "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:b6h0ql$2tva$1@digitaldaemon.com... > > void foo(out char[32] test) > > { > > } > > > > DMD gives the error that char[32] can't be an out parameter. > > > > I realize arrays are passed by reference implicitly. I was after more of > > the behavior you get when you return an array, but without the temporary. > > > > char[32] foo() > > { > > char[32] result; > > return result; > > } > > > > Oh well. I think it's by design. > > > > Sean > > > > > > |
April 03, 2003 Re: arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | > arrays can be inout ...
Ahh, I missed that one, sorry...
Thanks!
Luna Kid
|
April 03, 2003 Re: arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Sean L. Palmer wrote: > void foo(out char[32] test) > { > } > > DMD gives the error that char[32] can't be an out parameter. Static arrays can't be out parameters; making it a dynamic array will work fine. I think it's a compiler limitation, not lingual. > I realize arrays are passed by reference implicitly. I was after more of > the behavior you get when you return an array, but without the temporary. Static arrays are passed by content. I think the optimiser already does temporary return value removal. Walter said something along these lines in that thread advocating return variables, and it looks like a fairly easy one to pull off. |
April 04, 2003 Re: arrays can't be out parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | Burton Radons wrote: > > Sean L. Palmer wrote: > > void foo(out char[32] test) > > { > > } > > > > DMD gives the error that char[32] can't be an out parameter. > > Static arrays can't be out parameters; making it a dynamic array will work fine. I think it's a compiler limitation, not lingual. --------------------------------- Sorry, could you explain this. Do you think the D specification would allow it but it is not implemented? > > I realize arrays are passed by reference implicitly. I was after more of the behavior you get when you return an array, but without the temporary. > > Static arrays are passed by content. In any case? Or does this depend on in/out/inout? Only for small arrays this might make sense. I about 95% of all cases the C way of passing arrays by reference is more appropriate with respect to performance. > I think the optimiser already does > temporary return value removal. Walter said something along these lines > in that thread advocating return variables, and it looks like a fairly > easy one to pull off. Could you give me a hint how to find this thread? -- Helmut Leitner leitner@hls.via.at Graz, Austria www.hls-software.com |
Copyright © 1999-2021 by the D Language Foundation