Call by reference in SWIG?

Chris Mellon arkanes at
Thu Dec 11 20:02:26 CET 2008

On Thu, Dec 11, 2008 at 9:43 AM, Joe Strout <joe at> wrote:
> On Dec 10, 2008, at 10:19 PM, Nok wrote:
>> I can't get call-by-reference functions to work in SWIG...
> Python doesn't have any call-by-reference support at all [1], so I'm not
> surprised that a straight translation of the call-by-reference C function
> doesn't work.
> Unfortunately I don't know enough about SWIG to suggest a work-around.
>  Hopefully someone more versed in SWIG will have a bright idea.  If you
> don't find anything in the Python space, you might try poking around in Java
> references, since Java has the same call semantics as Python.

I'm not sure if SWIG has tools to do this for you or if you need to do
the mapping by hand, but the usual idiom is to translate them into
return values (keeping the original arg if the passed in value matters

More information about the Python-list mailing list