Re: Quick question on Glib style/design
- From: Jan Kratochvil <rcpt-gtk-devel-list AT gnome org jankratochvil net>
- To: muppet <scott asofyet org>
- Cc: gtk-devel-list gnome org
- Subject: Re: Quick question on Glib style/design
- Date: Wed, 4 Aug 2004 07:57:07 +0200
Hi,
On Wed, 04 Aug 2004 04:21:31 +0200, muppet wrote:
...
> not quite. notice that most gtk+ constructors return GtkWidget*?
I do not much understand why. GLib functions expect C type of the most far
ancestor type they need to access to be as general as possible. They usually
return the most far descendant class they create. Just why GTK+ has a style
where the constructor gtk_button_new() returns (GtkWidget *) and not its native
class (GtkButton *)? It is not much systematic this way.
It looks dangerous to me to cast a return value of a function to some
descendant class as I need to know the inner behavior of the constructor to be
allowed to cast it.
> GtkWidget * foo;
> GtkContainer * container;
>
> container = (GtkContainer*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
It would be more correct to cast by
container = GTK_CONTAINER (gtk_window_new (GTK_WINDOW_TOPLEVEL));
to get the proper class hierarchy checking.
Regards,
Lace
--
Jan Kratochvil; Captive: free r/w NTFS Filesystem; http://www.jankratochvil.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]