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

Re: [Sheflug] stupid C question [SOLVED]



Dear all,
	Ross has been kind enought to enligthen me on my C woes. <all
sing merrily>Thanks Ross!</allsingmerrily>

	Anyway, I included the message below for reference, but what's
happening is the fact that my_int_var is defined as an auto variable
inside a function. It then disappears as the function exits. Ross
suggested to either:
a) declare it as static
b) declare it in main and pass it on to the interface function

	Again, thanks both Ross and Alistair.
	José

> > *(int *)user_data = 9;  ?
> 
> 	Nice'n easy :) Thanks both Ross and Alastair for the answer.
> Now, more problems on the way... Let's assume that there's 3 functions
> in here: interface,callback1 and callback2. In interface() I call
> callback1 and callback2 with my pointer as per my previous message.
>   gtk_signal_connect (GTK_OBJECT (plot_ampl), "clicked",
>   		      GTK_SIGNAL_FUNC (callback1),
>      		      (gpointer)&my_int_var);
> 
>   void callback1(GtkEditable *editable, gpointer user_data);
>   void callback2(GtkEditable *editable, gpointer user_data);
> 		
> 	I want to make sure that callback1 updates the value of
> my_int_var to something else. I then want this updated value to be used
> by callback2. For a start, the value is defined as 1 in the interface()
> function. 
> 
> 	However, when an event makes the program go to callback1, the
> value in the pointer is a rosy 0, instead of 1. Any changes that I might
> make in callback1 are lost (in principle, I don't mind what value gets
> to callback1).

-- 
José L Gómez Dans			PhD student
					Radar & Communications Group
					Department of Electronic Engineering
					University of Sheffield UK
---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word 
 "unsubscribe" in the body of the message. 

  GNU the choice of a complete generation.