Re: radio button label



"Dugas, Alan" wrote:
> 
> BINGO!!!  Nice work Darin!  ...and thanks also to Jeff!  I don't understand why
> the changes in Darin's code work however.  The online documentation declares
> gtk_label_get() as follows;
> 
> void gtk_label_get(GtkLabel *label, gchar **str);
> 
> not
> 
> void gtk_label_get(GtkLabel *label, gchar *str);
> 
> Could either of you enlighten me?  Thanks in advance.
> 


This is a common C error with pointers.  Basically, the gtk_label_get
wants to tell the calling code where the string is.  The calling code
needs a char * type, to contain this information.  The intent of the
call is that the address, i.e. storage location, into which the location
of the desired string whould be written, it specified in the call. 
Clear as mud?  

So, if you use a variable on the stack or in memory, and specify the
address of that variable, the correct char * pointer value gets written
into that variable.

If you create a char ** variable, pointer to a pointer, and pass that
in, the gtk_label_get function will try to write the correct char *
pointer value into the location specified by the value of the char **
variable.  But, you've never set the value of the char ** to the address
of a valid pointer.  Hence, the write by gtk_label_get is attempted into
whatever random space corresponds to the data in that char ** memory.

Another valid construct (IIUC, barring tyops) could be:

gchar **radio_button_handle = (gchar **) NULL;
gchar *radio_button_label = NULL;

/* No casting should be required here, this is important,
   it shows that we are handling things properly */
radio_button_handle = &radio_button_label;

gtk_label_get(GTK_LABEL(label), radio_button_handle);
 


Hope that helps!

Using addresses of variables for function returns, and for input/output
parameters, is powerful but can get confusing, and the prototyping (even
if syntactically valid) does not capture the subtleties of some usages.

Eric Monsler




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