projects
/
profile
/
ivi
/
jansson.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
94182a5
)
Beautify the container_of macro
author
Petri Lehtinen
<petri@digip.org>
Thu, 12 Aug 2010 18:34:02 +0000
(21:34 +0300)
committer
Petri Lehtinen
<petri@digip.org>
Thu, 12 Aug 2010 18:34:51 +0000
(21:34 +0300)
Use offsetof instead of zero pointer dereference trickery.
src/jansson_private.h
patch
|
blob
|
history
diff --git
a/src/jansson_private.h
b/src/jansson_private.h
index
4490702
..
6d7e46c
100644
(file)
--- a/
src/jansson_private.h
+++ b/
src/jansson_private.h
@@
-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;