[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Sheflug] stupid C question
*(int *)user_data = 9; ?
-----Original Message-----
From: José Luis Gómez Dans [mailto:nospam [at] sheffield.ac.uk]
Sent: Friday, November 03, 2000 02:00
To: sheflug [at] vuw.ac.nz
Subject: [Sheflug] stupid C question
Hi!
This should be an easy one for seasoned C programmer. OK, I am
using GTK+ mixed with Fortran 95 in a project. The GTK+ bit and the
skeleton of the program is C, but I do use F95 routines to get the work
done. Due to this and the fact that the F95 compiler is _scary_ to say
the least (tends to corrupt some of the global variable space), I want
to minimize the number of global variables. So, without using global
variables (otherwise, solution would be easy!), let's start:
In a function (interface.c), I define several local variables. I
then want to pass them on to event call-backs using
gtk_signal_connect(). As an example
gtk_signal_connect (GTK_OBJECT (interferogram_polar), "clicked",
GTK_SIGNAL_FUNC (on_interogram_polar_clicked),
NULL) ;
Where the NULL can be exchanged by a variable that will be passed on to
on_interferogram_polar_clicked(). The latter is defined as
void
on_select_ampl_polaristaion_changed (GtkEditable *editable,
gpointer user_data) ;
and the NULL (or variable) goes in user_data.
Let's assume that I pass an integer. I do this by having
&my_int_var instead of the NULL in the gtk_signal_connect function. I
then do some processing in the callback handler, and end up with a new
integer value that needs to update the value of my_int_var in the first
function. How can I set this value?
The problem is that user_data is a gpointer (==void *), so I
cannot access it as I'd normally do with a pointer. This is illegal:
*user_data = 9 ; (say)
I can set user_data to a value in memory, but as soon as the
callback function dies, the value is cleared:
user_data = &callback_int ;
so the value in the main function isn't updated.
Graphically,
main<------Update value------------|
| |
| |
|----->callback->{change value}----|
It must be possible to do this without a global variable!!!
Thanks,
José
--
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.
---------------------------------------------------------------------
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.