<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 30, 2014 at 2:23 AM, Dominique Devienne <span dir="ltr"><<a href="mailto:ddevienne@gmail.com" target="_blank">ddevienne@gmail.com</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"> <div class="">On Wed, Jul 30, 2014 at 5:32 AM, Chris Cleeland <span dir="ltr"><<a href="mailto:chris.cleeland@gmail.com" target="_blank">chris.cleeland@gmail.com</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"> <div>In my case, the C API is stashing the value of the pointer in a container, and passing that pointer value as an argument to the registered callback function. That's it. The C code doesn't *do* anything with the pointer because it treats it as a void*.</div> </div></div></div></blockquote><div><br></div></div><div>Then it's a badly-designed C API I'm afraid...</div></div></div></div></blockquote><div><br></div><div>It's a well-documented pattern: <a href="http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf">http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf</a></div> <div><br></div><div>It's been around for years and years in the world of C. Super common in the X Toolkit and many other GUi frameworks.</div><div><br></div><div>The void* is just a value. It's convenient that it can hold a pointer, because then, rather than being a number that is an index in some kind of user container, it's can be an address.</div> <div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"> <div class="gmail_quote"><div><br></div><div>SQLite introduced a bunch of _v2 APIs (e.g. [1]) specifically to add a <span style="color:rgb(0,0,0)">void(*xDestroy)(void*) argument to some of its functions taking a void* user-data argument, to address lifetime issues. That's C programming done right, which interfaces just fine with C++ and shared_ptr and co.</span></div> </div></div></div></blockquote><div><br></div><div>Only if SQLite is doing something active with the void*.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"> <div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">The fact that one programs and designs APIs in C doesn't mean one shouldn't care about lifetimes. My $0.02. --DD</span></div> <div><br></div><div>[1] <a href="http://www.sqlite.org/capi3ref.html#sqlite3_create_module" target="_blank">http://www.sqlite.org/capi3ref.html#sqlite3_create_module</a> </div></div></div></div></blockquote><div><br></div> <div>It's really a matter of ownership, isn't it? Neither language supports the concept of shared ownership (save C++11 now with std::shared_ptr<>).<br><br>That triggered an interesting thought. I've been thinking of this all along as wanting the C API's holding of the pointer value for its ACT as counting as one of the reference counts. But really, it's just a value, and it's up to the callback function to decide if that value is valid. In that sense, it's almost like I want it to have the semantics of a weak_ptr<> so that the callback function can check the validity of the ACT before moving on. Interesting.</div> <div><br></div><div><br></div></div></div></div>