Mercurial > molko
diff libmlk-core/mlk/core/util.h @ 629:fee7bd30725c
rpg: cleanup tileset-loader-file
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 26 Aug 2023 16:09:35 +0200 |
parents | 509b395171f2 |
children | 3d238b43a9aa |
line wrap: on
line diff
--- a/libmlk-core/mlk/core/util.h Sat Aug 26 15:36:07 2023 +0200 +++ b/libmlk-core/mlk/core/util.h Sat Aug 26 16:09:35 2023 +0200 @@ -24,6 +24,7 @@ * \brief libmlk-core utilities */ +#include <stddef.h> #include <stdint.h> /** @@ -34,6 +35,12 @@ */ #define MLK_UTIL_SIZE(x) (sizeof ((x)) / sizeof ((x)[0])) +/** + * Obtain parent container from a member field. + */ +#define MLK_CONTAINER_OF(ptr, type, member) \ + ((type*)((char*)(1 ? (ptr) : &((type*)0)->member) - offsetof(type, member))) + #if defined(__cplusplus) extern "C" { #endif