[Newbie] When to use *_IS_* macro?



Hi,

In order to keep a code as clean as possible, I'm currently thinking about removing/adding code.

The current object of my thoughts is *_IS_* macros, using G_TYPE_CHECK_INSTANCE_TYPE. In which circumstance should we use this macro (and related) and when not use them?
My understanding is these macro allow safe "down-casting". So I need to use them when a cast is necessary, but avoid them in other case.

For exemple, in Gtk tutorial[1] I can read the following functions:
static void
gtk_dial_destroy (GtkObject *object)
{
  GtkDial *dial;

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_DIAL (object));

  dial = GTK_DIAL (object);

  if (dial->adjustment)
    gtk_object_unref (GTK_OBJECT (dial->adjustment));

  if (GTK_OBJECT_CLASS (parent_class)->destroy)
    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

GtkAdjustment*
gtk_dial_get_adjustment (GtkDial *dial)
{
  g_return_val_if_fail (dial != NULL, NULL);
  g_return_val_if_fail (GTK_IS_DIAL (dial), NULL);

  return dial->adjustment;
}


In my mind, GTK_IS_DIAL and GTK_DIAL are necessary in gtk_dial_destroy as the argument is not GtkDial but GtkObject.
In the other hand, GTK_IS_DIAL seems not necessary in gtk_dial_get_adjustment as C compiler will ensure (gruik cast excepted) that argument is in the right type.

Can I consider to remove *_IS_* in codes like gtk_dial_get_adjustment or is it a best practice to always call such macro?

[1] http://developer.gnome.org/gtk-tutorial/stable/x2310.html
--
Guilhem BONNEFILLE
-=- JID: guyou im apinc org MSN: guilhem_bonnefille hotmail com
-=- mailto:guilhem bonnefille gmail com
-=- http://nathguil.free.fr/



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