<div dir="ltr">Dear Marc, I was thinking, is the FFI (|c-define-type|) compatible with the C++ RAII in such a way that C++'s std::shared_ptr can be used as (c-define-type my-struct-shared "shared_ptr<my_struct>")?<br><br>shared_ptr is a refcounted slot, where the +1 and -1 refcount update is carried out by the RAII.<br><br>If I would not pass the std::shared_ptr as (c-define-type my-struct-shared "shared_ptr<my_struct>"), then instead I would wrap it in a C/C++ struct which then contains the std::shared_ptr as its only slot.<br><br>Please let me know your thoughts on what's the best approach.<br><br>Here is a test case:<br><br><br>(c-declare #<<c-declare-end<br><br>#include <memory><br><br>typedef struct my_struct<br>{<br>  int value;<br>} my_struct;<br>using namespace std;<br>c-declare-end<br> )<br>(c-define-type my-struct-shared "shared_ptr<my_struct>")<br><br>(define (make-my-struct)<br>  (c-lambda () my-struct-shared #<<c-lambda-end<br>      std::shared_ptr<my_struct> out = std::make_shared<my_struct>();<br>      out->value = 0;<br>      ___return(out);<br>c-lambda-end<br>    ))<br><br>(make-my-struct)<br><br><br>Gambit v4.9.3<br><br>> (load "shared_ptr")<br>"/path/to/shared_ptr.o2"<br>> (make-my-struct)<br>#<procedure #2 shared_ptr#0><br>> (define a (make-my-struct))<br>> a<br>#<procedure #2 shared_ptr#0><br><br><br>At least it does compile! Looking forward to your confirmation if this is safe & best practice.<br><br>( When I skip the "using namespace std;" and prepend "std::" to (c-define-type my-struct-shared "shared_ptr<my_struct>"), I do get weird compiler errors however. )<br><br>Phil<br></div>