Converting pointer to A into a pointer to structure B that A is embedded inside

82 Views Asked by At

In Pintos project, there is a macro that converting pointer like what I wrote in title.

#define list_entry(LIST_ELEM, STRUCT, MEMBER)
                     ((STRUCT *) ((uint8_t *) &(LIST_ELEM)->next
                     - offsetof (STRUCT, MEMBER.next)))

(at src/lib/kernel/list.h)

Why It is not like this?

#define list_entry(LIST_ELEM, STRUCT, MEMBER)
                     ((STRUCT *) ((uint8_t *)LIST_ELEM
                     - offsetof (STRUCT, MEMBER)))
0

There are 0 best solutions below