C programming language is not very popular nowadays. I don't care. I like the language.
It was very interesting to learn how linked lists are implemented in the Linux kernel. This picture illustrates them nicely:
A custom structure - the type of objects you want to enlist - contains `struct list_head' as its member. This is not a pointer (that's the point) and you can place it anywhere (!) within the structure (i.e., it doesn't have to be the first member).
You use list_head members for list operations (insertion, deletion, iteration, etc.; all the nice stuff defined in linux/list.h). And when you need the rest of your data structure — you use `list_entry' macro. `list_entry' fetches a pointer to the container object from its `struct list_head' member.
This is my "hello world" program (skip down to `struct Char' and `main' function):
( Collapse )