6 * container_of - routine for upcasting
8 * It is often convenient to create code where the caller registers a pointer
9 * to a generic structure and a callback. The callback might know that the
10 * pointer points to within a larger structure, and container_of gives a
11 * convenient and fairly type-safe way of returning to the enclosing structure.
13 * This idiom is an alternative to providing a void * pointer for every
18 * #include <ccan/container_of/container_of.h>
29 * static void register_timer(struct timer *timer)
34 * static void my_timer_callback(struct timer *timer)
36 * struct info *info = container_of(timer, struct info, timer);
37 * printf("my_stuff is %u\n", info->my_stuff);
42 * struct info info = { .my_stuff = 1 };
44 * register_timer(&info.timer);
49 * License: Public domain
50 * Author: Rusty Russell <rusty@rustcorp.com.au>
52 int main(int argc, char *argv[])
57 if (strcmp(argv[1], "depends") == 0) {
58 printf("ccan/check_type\n");