Warp wrote:
> Nicolas Alvarez <nic### [at] gmailcom> wrote:
>> A good approach (that few people use) is making the library in C++ and
>> making a C wrapper :)
>
> That would be rather difficult because it's not possible to call C++
> functions from C. (The C compiler cannot understand C++ name mangling,
> and obviously none of the features C++ has that C doesn't.)
Isn't this possible?
cwrap.h:
struct Foo_Obj; //fwd declaration
#ifdef __cplusplus
extern "C" {
#endif
struct Foo_Obj* foo_obj_create();
void foo_obj_dosomething(Foo_Obj* obj);
void foo_obj_delete(Foo_Obj* obj);
#ifdef __cplusplus
}
#endif
cwrap.cpp:
#include "foo.hpp"
struct Foo_Obj {
FooLib::Obj realthing;
};
extern "C" {
struct Foo_Obj* foo_obj_create() {
return new Foo_Obj;
}
void foo_obj_delete(struct Foo_Obj* obj) {
delete obj;
}
void foo_obj_dosomething(struct Foo_Obj* obj) {
obj->realthing.dosomething();
}
} //extern "C"
Post a reply to this message
|