compiled program error
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 7 12:05:15 PDT 2015
On Sunday, 7 June 2015 at 18:59:00 UTC, John Nixon wrote:
> double[] pvi,int_1,int_2;
>
> int_1=pvi_calc(centre);
> int_2=pvi_calc(n-1-centre);//pvi_calc is changing int_1!
> double[] pvi_calc(const int n1){
> return pvi;}
These are the relevant lines: pvi_calc writes to a global array
(pvi) then returns it.
So the first two lines are just setting int_1 and int_2 both to
pvi, the same thing. So since they all reference the same array,
writing to any of them changes all of them.
You'll probably want to move double[] pvi to inside pvi_calc so
it becomes a new copy, or at least `return pvi.dup;` instead of
just `return pvi;`
More information about the Digitalmars-d
mailing list