Re: g_(s)list_data()
- From: Derek Simkowiak <dereks realloc net>
- To: Joel Becker <jlbec evilplan org>
- Cc: gtk-devel-list gnome org
- Subject: Re: g_(s)list_data()
- Date: Thu, 24 May 2001 17:08:18 -0700 (PDT)
-> while (list)
-> {
-> Foo *foo = g_list_data(Foo *, list);
-> do_something(foo->obj);
-> list = g_list_next(list);
-> }
->
-> Which is very nice to read.
I disagree that this is nice to read. I'd prefer to just see the
typecast -- at least then a new user will know what's going on (instead of
needing to lookup yet another macro, especially one that doesn't exist
in any of the current code).
-> Face it, the cast will be explicitly typed in 90% of cases (1%
-> really want a gpointer, and the other 9% are GTK_FOO(list->data)
-> calls).
I agree that the typecasts are very common. I disagree that a
macro is cleaner than a typecast.
-> What do folks think? This can, of course, work for GSList too (and any
-> other ->data structs I've forgotten).
It would need to follow the "object-like" Glib naming convention
of
g_thing_action(GThing *thing, ... )
...that is, the first argument of your g_list_data() should be a
GList*. If anything, it would need to be g_list_data(GList *list,
Datatype*).
Although g_list_next() exists, it has been agreed that there is
way too much code that directly accesses list->next to deprecate that kind
of peeking. In short, even if list->next was meant to be private, through
real-world practice it has become public. And since list->data is already
public, there is no need for g_list_data().
As a frequent Glib user, if g_list_data() gets added, I will still
use list->data in all my code. Sorry :)
Derek Simkowiak
dereks at realloc dot net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]