Generating a C interface for a C++ library
Could someone point me at an accepted method for automagically exporting C declarations of a form similar to
extern "C" modified_fn(modified_Obj *o, args)
{
((Obj *)o)->fn(args);
}
based on C++ declarations of the form
class Obj
{
//...
Obj::fn(args)
//...
};
?
The idea being to ensure that a library has synchronised interfaces for use by programs written in both C and C++, with the minimum maintenance effort required.
I think you may be able to do it with macros but would rather be spoonfed than work it out myself *grin*. If it's possible, please point me at a source sample or an explanation. If it's not, or it's stupid or there's a better solution to the problem, please let me know ...
EDIT: by the way, I am aware of the difficulties introduced by overloaded methods in C++ ... can these be overcome here?
extern "C" modified_fn(modified_Obj *o, args)
{
((Obj *)o)->fn(args);
}
based on C++ declarations of the form
class Obj
{
//...
Obj::fn(args)
//...
};
?
The idea being to ensure that a library has synchronised interfaces for use by programs written in both C and C++, with the minimum maintenance effort required.
I think you may be able to do it with macros but would rather be spoonfed than work it out myself *grin*. If it's possible, please point me at a source sample or an explanation. If it's not, or it's stupid or there's a better solution to the problem, please let me know ...
EDIT: by the way, I am aware of the difficulties introduced by overloaded methods in C++ ... can these be overcome here?
