In the code of table.h for mysql. There are the following code
typedef struct st_table_share
{
...
struct st_table_share * next, /* Link to unused shares */
**prev;
in the text book, we usally have
sometype *next, *prev;
but here it use **prev instead of *prev. What the reason to use double pointer for prev?
It’s not pointing to the previous structure, as next is, it’s pointing to the pointer that’s pointing to this structure.
The benefit of doing this is that it can point to either the ‘next’ member of the preceding structure, or it can point to the actual head pointer itself – in the case where this is the first item in the list. This means that removing the item involves “*prev = next” in both cases – there’s no special case for updating the head pointer.
The downside is that you can’t (easily) use it to traverse the structure backwards; so it’s really designed to optimize the case where you only care about traversing forwards, but want to easily remove an arbitrary node.