]> git.ozlabs.org Git - ccan/blobdiff - container_of/container_of.h
Include all the tools under ccan_tools dir, hacked to work for me.
[ccan] / container_of / container_of.h
index 49f20b5670c99ddf5e6d98903c49e62912abf6ed..bdb23d07a163e2e0933568db35f0892c1dce7b5c 100644 (file)
@@ -5,6 +5,27 @@
 #include "config.h"
 #include "check_type/check_type.h"
 
+/**
+ * container_of - get pointer to enclosing structure
+ * @member_ptr: pointer to the structure member
+ * @containing_type: the type this member is within
+ * @member: the name of this member within the structure.
+ *
+ * Given a pointer to a member of a structure, this macro does pointer
+ * subtraction to return the pointer to the enclosing type.
+ *
+ * Example:
+ *     struct info
+ *     {
+ *             int some_other_field;
+ *             struct foo my_foo;
+ *     };
+ *
+ *     struct info *foo_to_info(struct foo *foop)
+ *     {
+ *             return container_of(foo, struct info, my_foo);
+ *     }
+ */
 #define container_of(member_ptr, containing_type, member)              \
         ((containing_type *)                                           \
          ((char *)(member_ptr) - offsetof(containing_type, member))    \