How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
I tried to pass pointer to static array but it didn't work.

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it works. if you really want to get some help, you'd better give us something to start with. i.e. your

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:20:55 UTC, drug wrote: I tried to pass pointer to static array but it didn't work. try this: import std.stdio; void change(ref int[3] arr) { arr[1] = 6; } void main() { int[3] a = [1, 2, 3]; writeln(a = , a); change(a); writeln(a = ,

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:20:55 UTC, drug wrote: I tried to pass pointer to static array but it didn't work. Also, if you really want to be lame and actually use a pointer try this: import std.stdio; void change(int *arr) { arr[1] = 6; } void main() { int[3] a = [1, 2, 3];

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[] arr) { arr[1] = 42; } void main () { int[$] a = [1, 2, 3]; change(a);

Re: How to pass static array to function not by value?

2014-11-22 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[]

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:57:40 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[]

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it works. if you really want to get some

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 16:07:25 UTC, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried

Re: How to pass static array to function not by value?

2014-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/22/2014 07:07 AM, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 08:07:31 -0800 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:26, Ali Çehreli wrote: On 11/22/2014 07:07 AM, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:26, Eric wrote: On Saturday, 22 November 2014 at 16:07:25 UTC, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:30, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 08:07:31 -0800 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 20:05:13 +0400 drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Does it worth to make some compiler option that for example prohibits passing static array instead of dynamic one without slicing? Who has a lot of breakable correct D code doesn't use

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 21:22, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 20:05:13 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: Does it worth to make some compiler option that for example prohibits passing static array instead of dynamic one without slicing?