D - arrays can't be out parameters?
- Sean L. Palmer (13/13) Apr 03 2003 void foo(out char[32] test)
- Luna Kid (5/18) Apr 03 2003 Hmm. Then, how does one modify an array in D
- Mike Wynn (28/53) Apr 03 2003 arrays are not arrays in the java/C sense, they are slices
- Luna Kid (3/4) Apr 03 2003 Ahh, I missed that one, sorry...
- Burton Radons (7/14) Apr 03 2003 Static arrays can't be out parameters; making it a dynamic array will
- Helmut Leitner (12/30) Apr 04 2003 ---------------------------------
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
Apr 03 2003
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
Apr 03 2003
"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...ofvoid 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 moretemporary.the behavior you get when you return an array, but without thechar[32] foo() { char[32] result; return result; } Oh well. I think it's by design. Sean
Apr 03 2003
arrays can be inout ...Ahh, I missed that one, sorry... Thanks! Luna Kid
Apr 03 2003
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.
Apr 03 2003
Burton Radons wrote:Sean L. Palmer wrote:--------------------------------- Sorry, could you explain this. Do you think the D specification would allow it but it is not implemented?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.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 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.Could you give me a hint how to find this thread? -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Apr 04 2003