Re: Parameter passing advice...



Hello Chris-

Chris Elston wrote:

A common "problem" when working the C version of GTK is the what's and
how's of passing parameters to signal handling functions.  If I'm not mistaken,
every "signal_connect" function ends in a gpointer (* void) parameter
which is there for the programmer to use for his own purpose(s).  Now,
I have experience with C but I'm no expert so this next question is both
related to that and my curiousity with GTK.

Sometimes, one parameter is not enough.  What methods have you all used in
the past to get around having only one gpointer at your disposal when you
need much more?  GLists?  Arrays?  some kind of hack around with regards
to the nature of void pointers?


If you want to pass more than one item of data into a signal handling
function
either:
  a.  make an array of the items (if they are all the same type), or
  b.  make a struct of the items (if they are of different types),

Once your data is grouped in one of the methods above, you can use one
single pointer (to the array or struct) to reach them.

Pass the pointer as the data arg (gpointer arg) into the signal or other 
function.  Once inside the function you reach your data using the
pointer.
It's not a hack; it's only one step of indirection.  A void pointer or
gpointer
is just a bucket (the largest pointer possible to hold any pointer type)
that
holds the pointer until you're inside the function.

amw18




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