Re: Passing Glists to callbacks



Adam wrote:
Hi all,
[...]

Any suggestions are of value.


Hi,
    Its hard to make out what exactly it is your doing...
it would be helpfull if you posted a short example
of code that doesn't work.

A common mistake when passing lists in as arguments to
a callback *that modifies the list* is when people pass
in the head node itself instead of its address, since
you almost always want to re-assign the head node after
any list operations.

i.e. the callback should look like:

gint
my_hash_foreach_list_accum (gpointer   key,
                            gpointer   value,
                            GList    **accum)
{
    if (frobnicate (key, value)) {
        *accum = g_list_prepend (*accum, value);
    }
}

Cheers,
                             -Tristan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]