Angus Mezick <angus@EDGIL.CCMAIL.COMPUSERVE.COM> writes:
> James,
> What does the example you give have to do with Macros?
>
> Your first example could be a Macro (the char_in_room(ch)) and the function
> still requires knowledge of the *next pointer.
>
> Your second example needs more code to make sense. How are
> chars_in_room_iterator(), next(), and iter_to_ch() defined for the present
> structure?
>
> All you have to be careful, C give you enoungh rope to tie a couple of nooses,
> just don't put you neck into it.
Here's a quick, tiny, implementation.
struct char_list {
struct list *next;
struct char_data *ch;
};
struct room {
struct obj_list *objects;
struct char_list *people;
...
};
struct char_data first_in_room(struct room *r)
{
assert(r);
assert(r->people);
return r->people->ch;
}
So, the following would work:
struct char_list *l;
for (l = first_in_room(r); l; l = l->next) {
blah(l->ch);
}
Or, we could do it like this:
struct iterator { /* or call it a general list */
struct iterator *next;
void *data;
};
Then implement similar to the above, with
iter_to_char(iterator *i);
simply casting and returning (perhaps at a later time having type
checking or something).
Iterator next() would simply return i->next.
Does this help any, or would more examples help things more?
--
James Turner turnerjh@xtn.net
http://www.vuse.vanderbilt.edu/~turnerj1/
+------------------------------------------------------------+
| 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/15/00 PST