Re: g_list_next(foo) vs. foo->next
- From: Tim Müller <t i m zen co uk>
- To: Neil Zanella <nzanella gmail com>, gtk-list gnome org
- Cc:
- Subject: Re: g_list_next(foo) vs. foo->next
- Date: Fri, 19 Nov 2004 09:25:50 +0000
On Thursday 18 November 2004 20:30, Neil Zanella wrote:
> I was just wondering whether
>
> g_list_next(foo)
>
> and
>
> foo->next
>
> are really the same or not. It seems to me that they are but
> that the former construct is preferable for object-oriented-like reasons.
~/src/cvs/glib/glib ---> grep g_list_next glist.h
#define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
So yes, they are basically the same, with the exception that you can use
g_list_next() on a NULL pointer, while you can't do that with l->next, so if
you have already checked for NULL anyway, like in
for (l = list; l; l = l->next) { ... do stuff ... }
you save the extra check that g_list_next() would introduce.
Which of the two you use is mostly a matter of personal preference; this is
really basic API that's very unlikely to change anytime soon. It's
definitively nothing to worry about, and if you check the Gtk+ source code
(for example), you'll see that both varieties are used.
Cheers
-Tim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]