help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: External C DLL crashes Octave


From: Jaroslav Hajek
Subject: Re: External C DLL crashes Octave
Date: Sat, 29 Aug 2009 07:36:32 +0200

On Fri, Aug 28, 2009 at 11:15 PM, mishrapiyush<address@hidden> wrote:
>
> Thank you Jaroslav and John. "double* A = B.fortran_vec()" worked like a
> charm! Just out of curiosity, I also tried type casting "double* A = (double
> *)B.data()" and that seems to work as well, but I have decided to go with
> fortran_vec.

If you're sure your function is not modifying the data, then that is
OK, and will actually be more efficient (no copying). Otherwise, it is
wrong. I'd suggest using const_cast in the former case - that is more
C++ish. Even better is to fix the called function so that it accepts
const double*.

> I also found that I was passing array in row-major format while
> Matlab and Fortran work on column-major format, so I had to pass transpose
> of original Matrix to ensure correct execution.

Octave also uses column-major format.

>
> John, the reason I am converting the pointer to double * is compatibility of
> my cpp code - to use the same code on both Matlab and Octave until I am
> confident of the port.

That's no problem - converting double * to a const double * is
automatic, so it's still a good idea to declare the argument const
double * if it is a read-only pointer.

> But, I want to ask you guys if I can return an array
> of double from my function as well? Can I just say:
>
> func1(C, A);
> retval(0) = C;
>
> where C is a pointer to doubles.
>

No. C must be one of the Array classes - NDArray, Matrix, ColumnVector etc.

regards

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]