Edit: I've edited my code to add the 'extern"C"' part (not sure if that makes a difference)
So I have this small code:
extern "C"{
void foo(int* nR,int* mR,float* x,float* out){ //&&
const int n=*nR,m=*mR;
other_foo(n,m,x,out);
}
}
that works fine. But now I want to copy the n-array of float x before passing it to
the function other_foo (since other_foo will be altering x and I want to keep a
copy).
if I do like so, all works fine:
extern "C"{
void foo(int* nR,int* mR,float* x,float* out){ //&&
const int n=*nR,m=*mR;
float y[n];
for(int i=0;i<n;i++) y[i]=x[i];
other_foo(n,m,x,out);
}
}
but if I do like so:
extern "C"{
void foo(int* nR,int* mR,float* x,float* out){ //&&
const int n=*nR,m=*mR;
float y[n];
std::copy(x,x+n,y);
other_foo(n,m,x,out);
}
}
all hell breaks lose: the output of other_foo is not the same anymore!
My question is, of course, why?