Beautify the container_of macro
Use offsetof instead of zero pointer dereference trickery.
This commit is contained in:
parent
94182a5acc
commit
519d52e2bb
@ -8,11 +8,12 @@
|
||||
#ifndef JANSSON_PRIVATE_H
|
||||
#define JANSSON_PRIVATE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user