struct list_head {

struct list_head *next, *prev;

The meaning of the elements is clear. next points to the next element, and prev points to the previous element. The list is also organized cyclically — in other words, the predecessor of the first list element is the last entry, and the successor of the last list element is the first entry.

Implementation of list functions is made more difficult by the following conditions:

□ The list elements need not be at the beginning of a structure, but may be located anywhere in the structure. Because list processing is supposed to function with any data types, this causes problems if a selected element is to be typecast into the target data type.

□ Several list elements can be used jointly in a structure so that they can be held in various lists.

List function implementation is based on a container mechanism provided by the kernel to embed objects in other objects. If structure A contains a substructure B, as in the following example, A is referred to as the container of B:

struct A {

} container;

When new elements are inserted in a list, the container property is not yet needed, as the following code of list_add shows:

Continue reading here: Info

Was this article helpful?

0 0