Praveen Srinivasan wrote:
Hi all,
Are there any important issues that one should be aware of when
calling C++ functions from C? In particular, I'm passing a function
pointer to a C routine in a library, and in that function I do C++
type stuff, e.g. utilizing operator overloading. Is that reasonable,
or are there some pitfalls I need to watch out for?
Are you doing callbacks?
You will not be able to pass member function pointers (C has no idea of
them). But I guess you know that. Another thing to remember is that as
soon as you do not pass pointers but call by name from C, you will need to
make the function extern "C" to get rid of the name mangling.
A third issue (unfortunately not important in most of todays C++ code) is
that it is very unhealthy to let the C++ exceptions escape from your C++
function into C! So if you have ANY chance of exceptions either make the
function throw() (so C++ will stop the app) or catch them all and ignore
them (and return error to the caller???).
A