Keywords: two-way linked list
In fact, it is relatively simple for experienced people to look down.
In the driver, insert all the disks found to the end of the two-way linked list (listhead), and then upload the nodes that meet the conditions to another linked list (disks. By default, the first node in listhead must meet the conditions and be inserted to the end of disks. After this action is completed, the link in the listhead changes when the second node is obtained. It looks strange.
List_entry listhead; list_entry disks; struct disk_info {list_entry entry ;...}... plistentry = listhead. flink; diskinfo = containing_record (plistentry, disk_info, entry); inserttaillist (& disks, & diskinfo-> entry); // (1) While (...) {plistentry = plistentry-> flink; // (2) In fact, at this time, plistentry-> flink does not match diskinfo0 = containing_record (plistentry, disk_info, entry );}
The discerning person may understand at first glance that at (1), the plistentry is linked to disks, so its flink has also changed, and it is no longer listhead. flink-> flink. In fact, this is equivalent to breaking a node from linked list 1 (not completely) and putting it in linked list 2. Its next node is definitely not the next node in the original linked list 1.
The expression capability is gradually improving...