Re: XForms: Global data

Kevin Smith (
Thu, 12 Mar 1998 16:51:48 -0800

# To subscribers of the xforms list from Kevin Smith <> :

Chris wrote:

> # To subscribers of the xforms list from Chris <> :
> I'm new at programming in X, and XForms is the first library I've really
> looked at in detail. I'm curious if there's a way to avoid using global
> data for a program using XForms? I can't see how passing variables
> (declared structures, etc) which haven't been declared globally, as
> parameters to callback functions which are called by xforms, is possible.
> If this issue has been brought up before, or if it's just general X
> programming, or if I'm not making any sense, could somebody point me in
> the right direction? My structures professor would kick my ass if I
> handed in a project with global data.

I'm writing a particle system in c/XForms and I've given up using
callbacks for anything serious. You have discovered the point
where, IMO, the forms library breaks down doing serious programming.
Any function that I need to get my data structures to ends up in
it's own function and called from the main loop like so....

while(do_main_loop == TRUE) {
main_return_object = fl_do_forms();
if (main_return_object == gui->PLAY) {
play = loop = TRUE;
} else if (main_return_object == gui->FRAME_ADV) {
play = TRUE;
loop = FALSE;

You can call your subroutines from main() and pass your data instead of
trying to do global pointers to linked lists of structures.

The xforms solution is to do this. In your "form".h you'll see...

typedef struct {
void *vdata;
char *cdata;
long ldata;

you can use these variables to pass data around. It's a kludge and your
better off grabbing the fl_do_forms()/fl_check_forms() output and writing
your own functions.

Disclaimer: I am more of a hack/self-taught programmer. I tried to use
globals and callbacks first, but all my pointers were weird and I couldn't
get anything to work right. Your mileage may vary.


==================================================== "I don't have a firm grip on reality, its got one on me and it won't let go."



_________________________________________________ To unsubscribe, send the message "unsubscribe" to or see XForms Home Page: List Archive: