<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 16, 2013 at 11:12 PM, Kristian Høgsberg <span dir="ltr"><<a href="mailto:krh@bitplanet.net" target="_blank">krh@bitplanet.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
> /**<br>
> * Retrieves a pointer to the containing struct of a given member item.<br>
> *<br>
> * This macro allows conversion from a pointer to a item, in a member called<br>
> * link, to its containing struct.<br>
<br>
</div>I think the 'in a member called link' phrase is a little odd, here,<br>
since we've not introduced anything called link. We're better off<br>
just leaving that out here, and then spelling it out in the example<br>
below.<br>
<div class="im"><br>
> This is useful if you have a contained<br>
> item<br>
> * like a wl_list, wl_listener, or wl_signal, provided via a callback or<br>
> other<br>
> * means and would like to retrieve the struct that contains it.<br>
> *<br>
> * To demonstrate, given a wl_list contained by a wl_resource, the<br>
> wl_resource<br>
<br>
</div>I would prefer an example that defines an example struct with a<br>
wl_list or wl_listener in it and then shows how to get from a pointer<br>
to that member to the containing struct. Using wl_resource is a<br>
little confusing, since it's an opaque struct and can't be used with<br>
wl_container_of outside the wayland libraries.<br></blockquote><div><br></div><div>Perhaps an example like this?<br><br></div> * \code<br> * struct foo_container {<br> * struct wl_listener destroy_listener;<br> * ... other members ...<br>
* };<br> *<br> * void foo_container_destroy(struct wl_listener *listener, void *data)<br> * {<br> * struct foo_container *container = NULL;<br> * my_foo = wl_container_of(listener, my_foo, destroy_listener);<br>
* <br>
* ... destroy my_foo ...<br> * }<br> * \endcode<br></div><br>-- <br>Aaron Faanes <<a href="mailto:dafrito@gmail.com" target="_blank">dafrito@gmail.com</a>>
</div></div>