[C++-SIG] Python calling C++ issues

David Beazley beazley at cs.uchicago.edu
Wed Dec 1 23:37:27 CET 1999


> 
> Gotcha.
> 
> IBM, that's who. It was IBM who insisted on the C++ standard specifiying that
> a pointer to an extern "C" function and a pointer to a C++ function with the
> same signature are type incompatible. Without this provision they claimed they 
> could not implement C++ on one of their mainframes. I don't have the article 
> in front of me but this point was the subject of a column in the C++ Report
> (Aug 99, I think). 
> 

Aiiiigh!!! Make it stop! Make it stop!

First off, I want to apologize for my out-of-line facist comment from
earlier--having spent far too much time trying to sort out changes in
the C++ spec recently has turned this into a hot-button for me (so
much so, I was about 30 seconds away from deleting all signs of C++
from my machines last month).

As for the casting to long issue, Geoffrey pointed out to me privately
that you can't do this if you care about inheritance which is, of
course, completely correct.   SWIG, although it does cast to a long at
some point in its internal pointer handling, also keeps track of type
information for this purpose.  For instance, depending on the type,
it is necessary to perform a casting operation to correctly adjust the
value of a pointer when cast from a derived class to a base class.
If you're extremely lucky, you can avoid this step and things will
work, but there's no guarantee that it will work everywhere and it
definitely won't work with multiple inheritance.

However, with that said, I'm still a big fan of keeping things as
simple as is reasonable.

As for the extern "C" issue, I would love to know how to officially
resolve that issue.  For now, I've solved it by simply slapping an
extern "C" around everything that gets hooked to Python (all wrapper
functions).  Still, it doesn't seem like a very satisfactory solution.
I have no idea what it implies for something like CXX.

Cheers,

Dave





More information about the Cplusplus-sig mailing list