Re: Example in Docs: GPOINTER_TO_INT



On Wed, May 30, 2001 at 07:15:36PM -0400, Brooklyn Linux Solutions wrote:

Greeting

What is GPOINTER_TO_INT in the example at:

http://developer.gnome.org/doc/API/gtk/gtk-signals.html#GTK-SIGNAL-CONNECT

______________________________________________________________________________
static void button_clicked_int(GtkButton* button, gpointer func_data)
 {
         g_print("button pressed: d\n", GPOINTER_TO_INT(func_data));
 }

 /* By calling this function, you will make the g_print above
  * execute, printing the number passed as `to_print'. */
 static void attach_print_signal(GtkButton* button, gint to_print)
 {
         gtk_signal_connect(GTK_OBJECT(button), "clicked",
                 GTK_SIGNAL_FUNC(button_clicked_int),
                 GINT_TO_POINTER(to_print));
 }

It's a cast, from a pointer to an int.  Equivalent to:

(gint) to_print

The example puts an int in the pointer "slot" instead of a pointer, by
casting it to the pointer type.  It then retrieves the number by casting
the pointer back to an int.

Maybe not the best example, but commonly used nonetheless.

Daniel.
-- 
*-*
Daniel Venkitachalam                                  venki-d ee uwa edu au
University of Western Australia                 swww.ee.uwa.edu.au/~venki-d
.... .  .  .   .    .     .      .       .        .         .             .  
___________________________________________________________________________




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