Re: XForms: C++ design wanted

Mark Edward Johnston (M.E.Johnston@damtp.cam.ac.uk)
Sat, 14 Jun 1997 18:25:42 +0100 (BST)

To subscribers of the xforms list from Mark Edward Johnston <M.E.Johnston@damtp.cam.ac.uk> :

On Sat, 14 Jun 1997, Kaz Kylheku wrote:

> Umm, what you are doing is passing a pointer to a C++ function to a subsystem
> that expects a pointer to a C callback function. Doesn't that violate some
> rule somewhere in the mighty C++ draft? ;)

Well I think you're correct.

(by the way the standard (actually the public review document) is at:
http://www.maths.warwick.ac.uk/c++/pub/wp/html/cd2/
)

Firstly, the type of a pointer to a static
member of type T is just plain "pointer to T" (see [expr.unary.op]),
rather than "pointer to member of type T", which is
good. However, there seems to be no way to make it a C function:
>From [dcl.link]: A non-C++ language linkage is ignored for the names of
class members and for the function type of class member function
declarators.

Thus what I'm giving to fl_set_object_callback() is indeed a pointer to a
C++ function.

I guess this means one really should make a C function which calls the
C++ member function, and register that C function as the callback.
eg.

extern "C" void BoundedFloatControl_callback(FL_OBJECT* obj, long data)
{
BoundedFloatControl::callback(FL_OBJECT* obj, long data);
}

...
fl_set_object_callback(slider, BoundedFloatControl_callback, 0);
...

What I've been doing seems to work, however (not that that's a great
recommendation to do it). Does anybody
know why it works, and if it is guaranteed to work on all compilers or
not ? I didn't find anything in the standard which says it should work.

Mark J.

---
Mark Johnston.                    M.E.Johnston@damtp.cam.ac.uk
816 King's College, Cambridge, CB2 1ST, U.K.
 or: DAMTP, Silver St., Cambridge, CB3 9EW, U.K.
'phone: (home) +44 1223 500 585 (has voice mail, let it ring!)
WWW: http://www.damtp.cam.ac.uk/user/mej20/

_________________________________________________ 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://bragg.phys.uwm.edu/xforms List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/