That worked a treat! Thank you very much!
On Thursday, 15 May 2014 at 21:11:54 UTC, Ali Çehreli wrote:
On 05/15/2014 01:55 PM, Andrew Brown wrote:
> extern(C) {
> void regress(int nInd, int nCov, ref double[] x, ref
double[] y, ref
> double[] rOut);
> }
I don't think that should even be allowed. C functions should
not know or be compatible with 'ref' D parameters. Define the
arguments as simple 'double *' or 'const double *'.
That makes sense because your C function is defined that way
anyway.
> void main(){
> int nInd = 5;
> int nCov = 3;
> double[] x = new double[nCov * nInd];
// ...
> regress(5, 3, x, y, residuals);
You want to pass the address of the first array member: x.ptr
(&(x[0]) would work as well). (Same for y.)
Otherwise, what ends up happening is that the address of the x
and y slices are passed and C has no idea of what that is.
Ali