ccan_tokenizer, check_type, container_of, typesafe_cb: handle !HAVE_TYPEOF
[ccan] / ccan / container_of / container_of.h
index de3f4505162a5416f477d5624e0049da6d2abeec..2a6b1cd54e9dcf97f57b0b282e23bb7de82ae0db 100644 (file)
  *             return i;
  *     }
  */
-#ifdef HAVE_TYPEOF
+#if HAVE_TYPEOF
 #define container_of_var(member_ptr, var, member) \
        container_of(member_ptr, typeof(*var), member)
 #else
-#define container_of_var(member_ptr, var, member) \
-       ((void *)((char *)(member_ptr) - offsetof(containing_type, member)))
+#define container_of_var(member_ptr, var, member)              \
+       ((void *)((char *)(member_ptr)                          \
+                 - ((char *)&(var)->member - (char *)(var))))
 #endif
 
 #endif /* CCAN_CONTAINER_OF_H */