Re: g_(s)list_data()



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]