Re: Quick question on Glib style/design



> Hello,
>
> I have a simple object hierarchy A<-B, and some base functions that take
> A* as a parameter:
>
> do_base (A*)
>
> Currently I have to cast B to A so I can use do_base because the C
> language doesn't know about my hierarchy. Since I'm forced to cast
> anyways, I was thinking of changing the functions to:
>
> do_base (gpointer)
>
> then casting gpointer to A inside.
>
> The declaration in the header will look weird, but it saves the
> programmer from manually casting.

Surely you will still have to cast to a gpointer (void*) just as much as
you would have to cast to A*, plus you'll have a totally obsure API. This
is C, and casting is part of the deal with gobject. Get a better
programming language if you want the language to do more work for you.

Something like gtk_widget_show(GtkWidget* widget) is an example of what
you want. People always need to cast derived widget pointers (such as
GtkTreeView*) to the base GtkWidget*, and people seem to have got used to
doing that.


Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com



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