]> git.itanic.dy.fi Git - sdl-planets/blobdiff - utils.h
quadtree: Add missing function definition to the header
[sdl-planets] / utils.h
diff --git a/utils.h b/utils.h
index b377038edd94a022114e0d84e40b9ed1c81a885a..bceaa27290a031ef0edbac49dd50392a436ae57f 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -4,4 +4,15 @@
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:       the pointer to the member.
+ * @type:      the type of the container struct this is embedded in.
+ * @member:    the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({                     \
+       const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+       (type *)( (char *)__mptr - offsetof(type,member) );})
+
 #endif