help-octave
[Top][All Lists]
Advanced

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

passing array from c function to c++ wrapper


From: grg
Subject: passing array from c function to c++ wrapper
Date: Tue, 1 Mar 2011 09:41:00 -0800 (PST)

Hi there,

I'm reposting this under a different title, so that the question does not
get lost.

I'm in the process of writing my first c++ wrapper for a c function.

I am stuck again, because I cannot pass back to C++ a vector from C. Instead
of the vector I get a logical. 
I've tried to read the Dal Segno Al Coda, DaCodaAlFine, but I am too
clueless about C++ to be able to understand those docs. 

Below is my code.   Please enlighten me! 
Many thanks in advance.
grg

--------------------------------------------------------------------------------
 
#include <stdlib.h> 
#include <stdio.h> 
#include <octave/oct.h> 
    
extern "C" 
{               
     double* t2 (double *x, int lenx) 
     { 
     int i; 
     double out[lenx-1]; 
                            
        for (i=0; i<=lenx-1; i++) 
        { 
            out[i]=x[i]*2; 
            printf ("%g\n", out[i]); 
        }                             
        return out; 
     } 
} 


DEFUN_DLD (t2, args, , "test interpolation") 
{ 
    octave_value_list retval;     
    Array<double> ar = args(0).array_value ();     
    retval(0) = octave_value( t2 (ar.fortran_vec(), ar.length()) ); 
        
  return retval ; 
} 


-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/passing-array-from-c-function-to-c-wrapper-tp3330243p3330243.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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