Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I convert to type SWIGTYPE_p_void in SWIG generated Java bindings?
    text
    copied!<p>I am developing some SWIG-generated Java bindings for a C library. The library contains functions that take parameters of type <code>void *</code>. On the C side these would typically be passed as a pointer to an array of type <code>float</code> or <code>int</code> cast to <code>void *</code>. In the generated Java bindings, this results in methods that take parameters of type <code>SWIGTYPE_p_void</code>.</p> <p>What is the best way to construct an array of floats/ints in the Java bindings so that they can be passed as type <code>SWIGTYPE_p_void</code> to these methods?</p> <p>At the moment I am defining a helper function in my example.i file:</p> <pre class="lang-c prettyprint-override"><code>void *floata_to_voidp(float f[]) { return (void *)f; } </code></pre> <p>And then on the Java side doing something like this:</p> <pre class="lang-java prettyprint-override"><code>float foo[] = new float[2]; SWIGTYPE_p_void av = null; // do something with foo av = example.floata_to_voidp(foo); example.myfunction(av); </code></pre> <p>This seems rather ugly, especially as I would also need an <code>inta_to_voidp()</code> etc in my SWIG interface file for each type conversion I want to support.</p> <p>Is there a way to do this without helper functions and involving less extra code on the Java side to convert data types?</p> <p><strong>UPDATE (17/6/12):</strong> to give additional detail to the question: what I'm trying to do is take a set of C functions, with prototype <code>int foo(const float *data, int N, const void *argv, float *result)</code> and map them to methods on the Java side where an array of arbitrary type can be passed in as <code>argv</code>. Note that <code>argv</code> is <code>const void *</code> and not <code>void *</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload