-
-
Save ultimateprogramer/83aeca704a904310025bbe45ba0125dd to your computer and use it in GitHub Desktop.
Revisions
-
ultimateprogramer revised this gist
Oct 27, 2022 . 6 changed files with 91 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // g++ simple.cpp -shared -o libsimple.dylib #include <stdio.h> class Simple { int id_; public: Simple(int id); ~Simple(); int id(); }; Simple::Simple(int id) : id_(id) { printf("[%p:%i] Simple()\n", this, id_); } Simple::~Simple() { printf("[%p:%i] ~Simple()\n", this, id_); } int Simple::id() { return id_; } extern "C" { Simple *Simple_Simple(int id) { return new Simple(id); } void Simple__gc(Simple *this_) { delete this_; } int Simple_id(Simple *this_) { return this_->id(); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ /* This is C code */ #include "Fred.h" void c_function(Fred* fred) { cplusplus_callback_function(fred); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ // This is C++ code #include "Fred.h" Fred::Fred() : a_(0) {} void Fred::wilma(int a) {} Fred* cplusplus_callback_function(Fred* fred) { fred->wilma(123); return fred; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ /* This header can be read by both C and C++ compilers */ #ifndef FRED_H #define FRED_H #ifdef __cplusplus class Fred { public: Fred(); void wilma(int); private: int a_; }; #else typedef struct Fred Fred; #endif #ifdef __cplusplus extern "C" { #endif #if defined(__STDC__) || defined(__cplusplus) extern void c_function(Fred*); /* ANSI C prototypes */ extern Fred* cplusplus_callback_function(Fred*); #else extern void c_function(); /* K&R style */ extern Fred* cplusplus_callback_function(); #endif #ifdef __cplusplus } #endif #endif /*FRED_H*/ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ // This is C++ code #include "Fred.h" int main() { Fred fred; c_function(&fred); // ... } -
gaspard created this gist
Jul 17, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ // g++ simple.cpp -shared -o libsimple.dylib #include <stdio.h> class Simple { int id_; public: Simple(int id); ~Simple(); int id(); }; Simple::Simple(int id) : id_(id) { printf("[%p:%i] Simple()\n", this, id_); } Simple::~Simple() { printf("[%p:%i] ~Simple()\n", this, id_); } int Simple::id() { return id_; } extern "C" { Simple *Simple_Simple(int id) { return new Simple(id); } void Simple__gc(Simple *this_) { delete this_; } int Simple_id(Simple *this_) { return this_->id(); } }