Re: [gtk-list] Passing pointer to structure of pointers to callback function



"Gordon M. Taylor" wrote:

>         Hello, all --
>
>         I am running a stock RedHat 6.0 system with Gnome 1.0 and GTK+ 1.2.1
>         installed.
>         I have applied all of the updates available in the updates/6.0/i386
>         directory from wuarchive.
>
>         Here is the problem that I am seeing...
>         Once I create a few widgets (window, windowbox, and button), I set
>         elements in a structure equal to them so that I can pass them to
>         callback functions for later manipulation.  If I pass that structure
>         from main() to the callback, everything works as expected.
>         However, if I call a function from main() (e.g. to create another
>         window), create the structure from within the second function
>         (window), and pass the structure to a callback function connected
>         to a button within this second window, the contents of the structure
>         are incorrect when printed from the callback function (and my program
>         segfaults when I try to manipulate one of those elements ;).
>
>         I have attached a small program that illustrates this below (sorry
>         for the size...).  I compiled this with the following command:
>     gcc -g `gtk-config --cflags` clientwindow.c -o a.out `gtk-config --libs`
>
>         What am I doing wrong?
>
>         Any help is greatly appreciated,
>
>         gordon
>

You're using local variables. You must use pointers to global (or malloc'ed)
variables.

Remember that the address of a local variable is not valid outside the function
where is declared.






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