Re: XForms: long data arg in callbacks?

Steve Lamont (spl@szechuan.ucsd.edu)
Fri, 6 Feb 98 18:34:29 PST

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I wanted to use the long data arg (2nd param) of the callback function as
> pointer to a struct. This way, I could access struct members from within
> the callback as
>
> data->memberVar1 = ...
> ... data->memberVar2 + ...

In my opinion, this is a bad idea. While a long generally is the same
length as a pointer, I'm not sure it's necessarily guaranteed to be (I
don't have my copy of the ANSI K&R to check at the moment).

A better way of passing pointers around is to use the u_vdata member
of the FL_OBJECT or FL_FORM structure or the vdata member of the FD_*
structure created by the create_form_*() functions.

> On the online manual, it says the callback routine should have the form
>
> void callback(FL_OBJECT *obj,long argument)
>
> Is there an intended purpose other than my own for the 2nd arg of object
> callback functions? Is it safe for me to use this long as a void*? Does
> anyone have any suggestions as to how to pass a struct pointer into my
> callback i.e. Motif's clientData?

The purpose is for passing user data and it's safe to use. I
generally use it as a way of differentiating between different objects
that use a common callback, say for a radio button.

Refer to the structure definitions in the `forms.h' file for detail.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/