Skip to content

Commit

Permalink
Beautify the container_of macro
Browse files Browse the repository at this point in the history
Use offsetof instead of zero pointer dereference trickery.
  • Loading branch information
akheron committed Aug 12, 2010
1 parent 94182a5 commit 519d52e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jansson_private.h
Expand Up @@ -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;
Expand Down

0 comments on commit 519d52e

Please sign in to comment.