Re: Quick question on Glib style/design

On Aug 3, 2004, at 10:16 PM, Ryan McDougall wrote:

On Tue, 2004-03-08 at 07:46 -0400, muppet wrote:


but this is also, in general, Not A Good Thing as you have totally sidestepped the compiler's type checking. for example, image somebody

But to me it seems as if Glib totally side-stepped C type checking anyways, since everything needs to be cast anyways.

not quite.  notice that most gtk+ constructors return GtkWidget*?

  GtkWidget * foo;
  GtkContainer * container;

  container = (GtkContainer*) gtk_window_new (GTK_WINDOW_TOPLEVEL);

  /* no casts necessary here */
  foo = gtk_button_new ();
  gtk_widget_show (foo);
  gtk_container_add (container, foo);
  gtk_container_set_border_width (container, 6);

and the compiler will warn me if i do the wrong thing, such as trying to pass container to gtk_widget_show(). thus, you use the cast macro, which usually expands to a run-time type check:

  gtk_widget_show (GTK_WIDGET (container));

"Quit hittin' yourself!  Quit hittin' yourself!"
   -- Elysse, playing with a newborn baby.

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