Re: why do constructors return GtkWidget?

On Tue, Sep 8, 2009 at 12:54 PM, Emmanuel
Touzery<emmanuel touzery free fr> wrote:

Whatever type is returned, you'll have to do lots of casts, so whatever
convention is used, there's no avoiding that. And returning GtkWidget*
is just the current convention.
I personally would prefer correct types to be used in the API, just to
show exactly what type to expect at runtime. But that's a separate

Thank you for the answer. If it doesn't make a technical difference I think
returning the actual type would be much more useful, for documentation
purposes. In the case of gtk_menu_shell_append() from the prototype you
would think that it can take any GtkWidget and only the comment tells you
that only GtkMenuItem* will do.

There is a technical difference when writing GTK+ code in C; for instance
its quite often that you will access methods on the GtkWidgetClass
(like show()/hide()/set_sensitive() etc), also many other apis take GtkWidget *
argument, namely GtkContainer apis which operate on child widgets.

From this standpoint its alot more convenient to cast all your widget variables
as GtkWidget * (this way you keep casting to a minimum in your code) so GTK+
is only helping you by returning GtkWidget *, if only for a simple and
reason to save you a little casting/typing.


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