<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">&lt;<a href="mailto:ddevienne@gmail.com" target="_blank">ddevienne@gmail.com</a>&gt;</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">&lt;<a href="mailto:chris.cleeland@gmail.com" target="_blank">chris.cleeland@gmail.com</a>&gt;</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&#39;s it.  The C code doesn&#39;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&#39;s a badly-designed C API I&#39;m afraid...</div></div></div></div></blockquote><div><br></div><div>It&#39;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&#39;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&#39;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&#39;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&#39;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&#39;t mean one shouldn&#39;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&#39;s really a matter of ownership, isn&#39;t it?  Neither language supports the concept of shared ownership (save C++11 now with std::shared_ptr&lt;&gt;).<br><br>That triggered an interesting thought.  I&#39;ve been thinking of this all along as wanting the C API&#39;s holding of the pointer value for its ACT as counting as one of the reference counts. But really, it&#39;s just a value, and it&#39;s up to the callback function to decide if that value is valid.  In that sense, it&#39;s almost like I want it to have the semantics of a weak_ptr&lt;&gt; 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>