Re: Question about GTK+ and timers

On Fri, 8 Apr 2011 21:03:47 +0100
Robert Pearce <rob bdt-home demon co uk> wrote:
> On Fri, 8 Apr 2011, Igor Korot <ikorot01 gmail com> wrote :
> >
> >My (hopefully last) question here in this thread is: g_io_add_watch()
> >should take a callback (i.e. static function) or just a regular
> >function?
> Are you writing in C or C++? I assume you're using the straight Gtk
> for C as the function g_io_add_watch belongs to that and we're on the 
> gtk-list rather than the gtkmm one.
> Anyway, the function you need to pass is a callback, so it needs to
> be a straight C function not a C++ class member. It doesn't need to
> be "static" in the C sense.

But it should be made static in the C sense if you don't want to export
it, and usually callbacks are local and don't need to be (and therefore
shouldn't be) exported. Polluting global namespace/linkspace with
functions with external linkage should be restricted to the cases where
it is necessary.

If the OP intended to refer to using C++ static member functions as
callbacks, the best advice is not to, because C++ static member
functions have C++ linkage specification and therefore might use a
different calling convention from those with C linkage.  (As it
happens, with gcc this doesn't matter; but technically it is undefined


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]