"Module":"container_of",
"Title":"container_of - routine for upcasting",
"Author":"dinesh",
"Dependencies":[
{
"depends":"ccan/check_type"
},
]
"Description":[
{
"str":""
},
{
"str":"It is often convenient to create code where the caller registers a pointer"
},
{
"str":"to a generic structure and a callback.  The callback might know that the"
},
{
"str":"pointer points to within a larger structure, and container_of gives a"
},
{
"str":"convenient and fairly type-safe way of returning to the enclosing structure."
},
{
"str":""
},
{
"str":"This idiom is an alternative to providing a void * pointer for every"
},
{
"str":"callback."
},
{
"str":""
},
{
"str":"Example:"
},
{
"str":"	struct info"
},
{
"str":"	{"
},
{
"str":"		int my_stuff;"
},
{
"str":"		struct timer timer;"
},
{
"str":"	};"
},
{
"str":""
},
{
"str":"	static void my_timer_callback(struct timer *timer)"
},
{
"str":"	{"
},
{
"str":"		struct info *info = container_of(timer, struct info, timer);"
},
{
"str":"		printf("my_stuff is %u\n", info->my_stuff);"
},
{
"str":"	}"
},
{
"str":""
},
{
"str":"	int main()"
},
{
"str":"	{"
},
{
"str":"		struct info info = { .my_stuff = 1 };"
},
{
"str":""
},
{
"str":"		register_timer(&info.timer);"
},
{
"str":"		..."
},
]
