Re: g_(s)list_data()
- From: Darin Adler <darin bentspoon com>
- To: Joel Becker <jlbec evilplan org>
- Cc: gtk-devel-list gnome org
- Subject: Re: g_(s)list_data()
- Date: Thu, 24 May 2001 16:10:11 -0700
On Thursday, May 24, 2001, at 03:50 PM, Joel Becker wrote:
We've all noticed that it is kinda weird to have g_list_next()
as an accessor macro, but use list->data as the data accessor. But
we've never put g_list_data() into the code, because no one felt it
important enough.
My approach was to ignore the g_list_next accessor macro.
Everyone right now has code
while (list)
{
Foo *foo = (Foo *)list->data;
do_something(foo->obj);
list = g_list_next(list);
}
or the uglier
while (list)
{
do_something(((Foo *)list->data)->obj);
list = g_list_next(list);
}
Taking advantage of C's special rules for void *, you can just do:
while (list)
{
Foo *foo = list->data;
do_something(foo->obj);
list = g_list_next(list);
}
or actually this, which is more like how we do it in Nautilus code:
for (node = list; node != NULL; node = node->next) {
Foo *foo = list->data;
do_something(foo->obj);
}
I don't think that another accessor would be a big help.
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]