Re: XForms: C++ design wanted

Mark Edward Johnston (
Sat, 14 Jun 1997 18:25:42 +0100 (BST)

To subscribers of the xforms list from Mark Edward Johnston <> :

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:

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 []: A non-C++ language linkage is ignored for the names of
class members and for the function type of class member function

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.

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.          
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!)

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