[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: passing array from c++ wrapper to c function
From: |
c. |
Subject: |
Re: passing array from c++ wrapper to c function |
Date: |
Mon, 28 Feb 2011 20:29:34 +0100 |
On 28 Feb 2011, at 19:23, grg wrote:
> Hi there,
>
> I'm a total ignorant about C and C++, yet I'd like to create an .oct file
> that allows me to run a C function from octave.
>
> I'm stuck, because I cannot understand how to pass a double array from C++
> to C.
>
> I've searched the web extensively, but haven't found much help (probably
> because of my ignorance).
>
> Can you suggest a solution, please?
>
> Thanks!
> grg
The following works for me:
-------------8<----------------
#include <stdio.h>
#include <octave/oct.h>
extern "C"
{
double t (double *x)
{
printf ("%g\n", x[1]);
printf ("%g\n", x[2]);
return 0;
}
}
DEFUN_DLD (t, args, , "test interpolation")
{
octave_value_list retval;
Array<double> ar = args(0).array_value ();
retval(0) = octave_value (t (ar.fortran_vec ()));
return (retval);
}
-------------8<----------------
>> mkoctfile t.cc
>> t ([1 2 3])
2
3
ans = 0
>>