Re: Why is cast from NULL illegal?



Lars Clausen <lrclause cs uiuc edu> writes:

> After changing Dia's code to have more static type checking, I'm getting a
> number of errors about invalid casts from NULL.  But surely NULL can be any
> type, so any cast of it should be valid.
> 
> The function in question here is gtk_item_factory_get_item(), which despite
> always returning NULL or a GtkMenuItem* has a return type of GtkWidget*.
> After some nasty bugs caused by the lack of static type check for this, I
> decided to make better use of the compilers typechecking.  But if I say
> GTK_MENU_ITEM(gtk_item_factory_get_item(...)), I get warnings whenever it
> returns NULL.  Having to check for NULL before casting would be
> cumbersome.  
> 
> So: Is there any good reason why the (or some) type check macros don't
> consider NULL to be of their type?

No particular good reason that I can recall ... it's been discussed
various times on gtk-devel-list and privately, but we never got around
to making the change.

It would be a compatible addition, so why don't you file a bug on
bugzilla.gnome.org to allow it so we don't forget about the issue?
(product glib, component gobject)

Thanks,
                                        Owen



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