22 Jul, 2009, JohnnyStarr wrote in the 1st comment:
Votes: 0
for (d = descriptor_list; d != NULL; d = d_next) { d_next = d->next;
ok, so the above is just a quick example of something that eludes me. I am wondering why the pointer var d_next is used instead of the typical "d = d->next" within the for statement.
I've been studying ROM and have noticed with the descriptors this is usually done this way, as where iterating through an object list it just uses "for(obj = object_list; obj != NULL; obj = obj->next)
Sorry if this is a dumb question, i'm sure theres a good reason and i appreciate the time you guys take to answer these things :wink:
22 Jul, 2009, David Haley wrote in the 2nd comment:
Votes: 0
The basic idea is that something can be removed from the linked list during iteration.
E.g., if d->time_since_last_command > IDLE_TIMEOUT, then remove d.
If that happens, d->next is no longer valid, because it has been removed from the list of descriptors.
So, one solution to this problem – of needing to know d->next after you might have removed it – is just to store it in d_next.
ok, so the above is just a quick example of something that eludes me.
I am wondering why the pointer var d_next is used instead of the typical "d = d->next" within
the for statement.
I've been studying ROM and have noticed with the descriptors this is usually done this way, as where
iterating through an object list it just uses "for(obj = object_list; obj != NULL; obj = obj->next)
Sorry if this is a dumb question, i'm sure theres a good reason and i appreciate the time you guys take to
answer these things :wink: