Subject: Re: C++, GLUT, and function pointers.
To: Ingolf Steinbach <Ingolf.Steinbach@jena-optronik.de>
From: Richard Rauch <rkr@olib.org>
List: netbsd-help
Date: 09/11/2003 10:14:31
On Thu, Sep 11, 2003 at 04:24:01PM +0200, Ingolf Steinbach wrote:
> Richard Rauch wrote:
> > So, if I understand the thread correctly, I can register this callback:
> >
> > extern "C" static void callback_fun(int button, int state, int x, int
> > y);
> >
> > from my C++ class:
> >
> > glutMouseFunc (callback_fun);
> >
> > ...and have callback_fun() call my class?
>
> Yes, this should work (provided callback_fun matches the
> signature expected by glutMouseFunc()). The only drawbacks
> are
Just tried. I get the same visible behavior: Most of it works, but
the scroll-wheel crashes.
Also, my compiler complains about multiple storage classes in
the declaration if I have both {extern "C"} and {static}.
(This is g++ 3.3.) So, I had to remove the {static}. Now I
have name-space pollution. (sigh)
> - one additional level of function calls
I can live with that. GLUT is a graphic library, and the callbacks are
for handling X events (translated into GLUT events...), so this is a
drop in the bucket I think. (^&
> - you'd have to make the static member function public to
> access it from callback_fun()
That's not as bad as the name-space pollution I mention above.
I consider the uglification of the source code to be the biggest drawback.
Where before I had one glut*() function to register the callback (plus
the "real" callback code), I now have:
register_*(void) in the root to register the callback.
extern "C" void ... (...) for the real callback.
register_*() INVOCATION in the specific classes.
the original callback code in the class
the original glut*() call modified to register the C callback
...and it still crashes the same way.
(And, yes, I converted every callback, not just the mouse-button
callback that seemed to directly crash me.)
I guess that it's not a total waste if ISO C++ really requires the
interface to be done this way.
The upshot seems to be that this has had no effect on the bug.
> Good luck
Thanks. It looks like I need it. (^&
> --
>
> Ingolf Steinbach Jena-Optronik GmbH
> ingolf.steinbach@jena-optronik.de ++49 3641 200-147
> PGP: 0x7B3B5661 213C 828E 0C92 16B5 05D0 4D5B A324 EC04
>
--
"I probably don't know what I'm talking about." http://www.olib.org/~rkr/