From: Petri Lehtinen Date: Thu, 12 Aug 2010 18:34:02 +0000 (+0300) Subject: Beautify the container_of macro X-Git-Tag: v2.0~43^2~2 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=commitdiff_plain;h=519d52e2bb6a3840100a84e826d8d8ac91e2d3d8 Beautify the container_of macro Use offsetof instead of zero pointer dereference trickery. --- diff --git a/src/jansson_private.h b/src/jansson_private.h index 4490702..6d7e46c 100644 --- a/src/jansson_private.h +++ b/src/jansson_private.h @@ -8,11 +8,12 @@ #ifndef JANSSON_PRIVATE_H #define JANSSON_PRIVATE_H +#include #include "jansson.h" #include "hashtable.h" #define container_of(ptr_, type_, member_) \ - ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) + ((type_ *)((char *)ptr_ - offsetof(type_, member_))) typedef struct { json_t json;