Re: g_list_foreach w/o user_data



on 10/26/01 10:24 AM, Daniel Elstner at daniel elstner gmx net wrote:

> I just saw this piece of code in GTK+ 1.3:
> 
> g_list_foreach (info->icon_list,
>                 (GFunc) g_object_unref, NULL);
> 
> This casts a 1-arg-function pointer to a 2-arg-function pointer.
> Doesn't that depend heavily on the compiler's function call model?
> How portable is it, actually?

The typical use of the signal handling machinery in gtk relies on this sort
of thing all the time. There are tons of places that pass functions that
take fewer parameters as handlers for signals that take more parameters.

It's true that this does depend on the compiler's function call model. But
not "heavily". It's extremely portable in practice.

I have worked on many other projects that avoided this kind of assumption,
but it's fundamental to how C is used in glib and gtk.

    -- Darin




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