in reply to perl XS - passing array to C and getting it back
return the array
You cannot return an array from a C function. Your c code example is returning the modified value of the first element of the array passed (by reference).
That means that in the following C calling code:
... double rv = 0, ary[ 10 ] = { 0, }; rv = do_nothing( ary, sizeof( ary );
After the call, rv would contain 1.0, the modified value of ary 0 ; and ary would have been modified to contain 10 x 1.0.
So what do you want the function -- as seen from Perl - to do?
All of these are possible, but only the first can be written in C alone; all the others would need to be written in XS code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl XS - passing array to C and getting it back
by kopolov (Acolyte) on Mar 29, 2016 at 12:44 UTC | |
by BrowserUk (Patriarch) on Mar 29, 2016 at 13:03 UTC | |
by kopolov (Acolyte) on Mar 29, 2016 at 13:11 UTC | |
by Corion (Patriarch) on Mar 29, 2016 at 13:20 UTC | |
by BrowserUk (Patriarch) on Mar 29, 2016 at 13:35 UTC | |
by Tux (Canon) on Mar 29, 2016 at 13:56 UTC |