2 ms·
The linux kernel has a cool linked list implementation for purposes like this, which IMHO is much prettier. Essentially you put a struct list (or hlist) inside
by sophacles 15y ago
The linux kernel has a cool linked list implementation for purposes like this, which IMHO is much prettier. Essentially you put a struct list (or hlist) inside of a struct you use in a list. This struct can be a simple pointer to data, or a full struct itself. Whatever. Then the list macros and functions just work on your data structure.
Implementation details here: http://lxr.linux.no/linux+v3.3/include/linux/rculist.h http://lxr.linux.no/linux+v3.3/include/linux/rculist.h
(also look up list.h).
My favorite part is wrapping your head round the container_of macro central to this. ( http://lxr.linux.no/linux+v3.3/tools/perf/util/include/linux/kernel.h#L26 http://lxr.linux.no/linux+v3.3/tools/perf/util/include/linux... )
Not that function pointers aren't neat or useful, but sometimes there are other cool solutions too :)