>There was quite a bit of discussion a long time ago >about using <struct>->next in loop conditions. >If I remember correctly, it could all be summarized with: >don't do it. > >Do something instead like: >while (temp && next_temp && (next_temp != obj)) { > next_temp = temp->next; > etc. >} The dangerous code is something like: for (ch = character_list; ch; ch = ch->next) { do_some_bad_stuff(ch); } If do_some_bad_stuff() is bad, e.g. can possibly kill ch. If ch dies, he is immediately extracted and freed (if a MOB), causing a segfault when the (now invalid) ch is dereferenced at the statement (ch = ch->next). This is the reason for the common construct found througout the code: for (ch = character_list; ch; ch = next_ch) { next_ch = ch->next; do_some_bad_stuff(ch); } I didn't see the original post on this topic, but this type of error might be why you're getting segfaults when trying to extract something. Make sure you save a copy of the obj->next pointer before trying to do anything to obj (especially extracting obj, which free()'s it!) -Jeremy +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST