void add(double a, double b, double *result) {
*result = a + b;
}
A human reader understands, that this function is storing a „return“ value in the double *result parameter. However, SWIG has no way to know that this is the underlying behavior. One way to deal with this problem is to use the typemaps.i library.
The corresonding code looks like this:
%module example
%include "typemaps.i"
%apply double *OUTPUT { double *result };
%inline %{
extern void add(double a, double b, double *result);
%}
See example „typemaps1“
using the module:
>>> import example
>>> example.add(3,4)
7.0