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.
22 Jul, 2009, Koron wrote in the 3rd comment:
Votes: 0
In this case, d might become null before the for loop ends and if that happens without a d_next, your mud would crash. This saves you that headache.

Edit: Woo near simultaneous postings!
22 Jul, 2009, JohnnyStarr wrote in the 4th comment:
Votes: 0
sweet, that makes total sense!

i snagged the snip from the do_shutdown() function so that makes sense.

cheers!
0.0/4