hard20 pts · first answer countsembedded-cpointers
Recovering the parent struct
A list stores pointers to struct node embedded inside struct timer. Given struct node *n, how does container_of get the timer?
struct node { struct node *next; };
struct timer { uint32_t period; struct node link; };
#define container_of(p, T, m) ((T *)((char *)(p) - offsetof(T, m)))
struct timer *t = container_of(n, struct timer, link);Discussion 0
Join free to post in the discussion.
Related questions
- Why use volatileEmbedded Systems Engineer
- Setting a register bitEmbedded Systems Engineer
- Reading a hex register valueEmbedded Systems Engineer
- Adding to a uint8_t counterEmbedded Systems Engineer
- Where const goes in a pointerEmbedded Systems Engineer
- A static local counterEmbedded Systems Engineer
- Why a cross-compilerEmbedded Systems Engineer
- Keeping a table out of RAMEmbedded Systems Engineer