Re: Transmit an array to a function
- From: amw18 home com
- To: Raymond Wan <rwan cs mu oz au>, gtk-list gnome org
- Subject: Re: Transmit an array to a function
- Date: Thu, 05 Jul 2001 07:25:21 -0400
Raymond Wan wrote:
> On Thu, 5 Jul 2001, Anthony Ferrand wrote:
> > > I'm not sure about it but try this :
> > > gtk_signal_connect (GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(function),
> > > widget);
> > > according that widget is the name of your array (GtkWidget *widget)
> > > This should work, I think (thought I never tried it...)
When I see the word 'transmit' I wonder if you are taking advantage of
the most useful aspect of a pointer.
You may be doing the best thing already, but in case you are not. . .
In most cases (especially when the array or struct is large) you prefer
copy the array into the function, but only to pass the address of the
into the function so that the array continues to be accessible inside
function (as it was before the function). When this can be done it
the time of copying the array to a new place in memory and saves the
The way to do this is to put the address of the array into a gpointer
(or a void pointer or any generic pointer designed to be large enough to
hold all pointer sizes), pass the gpointer into the function as an
and within the function put the address back into a pointer of the
Once you have the address of the array inside the function in a pointer
with a type, you can access the array using that pointer.
The 4th argument of the function gtk_signal_connect() is a gpointer
designed to do exactly this.
I'm new to GTK+, but as a long-time C programmer I recognized the value
this code immediately.
] [Thread Prev