[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: External C DLL crashes Octave
From: |
John W. Eaton |
Subject: |
Re: External C DLL crashes Octave |
Date: |
Fri, 28 Aug 2009 16:08:29 -0400 |
On 28-Aug-2009, Jaroslav Hajek wrote:
| On Fri, Aug 28, 2009 at 9:44 PM, mishrapiyush<address@hidden> wrote:
| >
| > Tatsuro,
| >
| > Thanks for replying to promptly.. I am using Octave 3.2.0, which is the
| > latest Win binary. I believe it is the MinGW version. I am able to compile
| > and call the sample application (d_gcc) but was having problem with my Cpp
| > code.
| >
| > In the meantime, I have found the reason of crash - it was due to an
| > error in my DEFUN_DLD function. Basically, I want to pass an array of
| > Doubles to my C function, say, as follows:
| > x = [10 100 1000 10000] %array of Doubles
| > mycodewrapper(x) %containing func1
| >
| > as stated earlier, func1 is defined as follows:
| > extern "C" unsigned int func1(double *x);
| >
| > I have tried:
| > Matrix B = args(0).matrix_value();
| > double* A = B.Rep->data;"
| > but rep is now protected and hence compilation fails.
| >
| > Could you recommend a good way to convert args of DEFUN_DLD into a pointer
| > of doubles. Is there a variation on "double* A = B.data()" which will allow
| > me to cast const double* to double*?
| >
|
| B.Rep->data would be wrong anyway. B.fortran_vec() correctly extracts
| a writable pointer.
Jaroslav is correct, but does your function actually need to modify
its argument? If not, better to declare the argument "const double*"
and then pas "B.data ()" to your function. Also, arguments passed to
Octave functions are strictly copy on write, so any modification you
do make to the contents of B will not appear in the calling context
unless you explicitly return the modified value as an output from your
function.
jwe
Re: External C DLL crashes Octave, Benjamin Lindner, 2009/08/30