[C++-sig] call C-functions (by reference) from Python (using Boost.Python)

David Abrahams dave at boost-consulting.com
Thu Dec 7 16:43:01 CET 2006

<Lutz.Lauterbach at qimonda.com> writes:

> Please do not say "Boost.Python was designed for C++ and not for C, so
> better use SWIG or whatever", because I am sold on the
> "minimal-invasive" methodology of Boost.Python which makes us able to
> use/develop our C-code even further (in C).

One thing to watch out for: Boost.Python works by operating on
function pointers, and these two types are different in principle:

  typedef void (*t1)(int);
  typedef extern "C" void (*t2)(int);

Many compilers will treat them interchangeably, but I think
Boost.Python doesn't contain the overloads required to handle extern
"C" functions when they're not interchangeable with C++ functions.  So
to export these functions portably you may need to wrap them in C++
functions.  Py++ could of course automate that, but Roman would have
to program it.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list