RE: Using g_signal_connect in class



Thanks for the linkage info Chris.  I've been using static class members
successfully with the Sun compiler on Solaris, but I'll start declaring
my callbacks with c linkage to be standard conforming.  Sun's
documentation gives the same advice:
https://developers.sun.com/solaris/articles/mixing.html
   
-Anthony Vallone

-----Original Message-----
From: gtk-list-bounces gnome org [mailto:gtk-list-bounces gnome org] On
Behalf Of Chris Vine
Sent: Saturday, July 19, 2008 4:51 PM
To: Milosz Derezynski
Cc: gtk-list gnome org; Vallone, Anthony
Subject: Re: Using g_signal_connect in class

On Sat, 19 Jul 2008 16:40:17 +0200
"Milosz Derezynski" <internalerror gmail com> wrote:

> I think he meant that in order to use the function with 
> g_signal_connect(), a C linkage is not needed (and i think this is 
> actually right, too).

No, g_signal_connect() takes a function pointer and in C++ function
pointers have a linkage type.  For GObject/GTK functions they have C
linkage type.

By default, when compiled in a C++ environment non-member functions and
non-member function pointers have C++ linkage type, so that amongst
other things functions can be overloaded, but some compilers may also
keep arguments on the stack for function calls with C linkage
differently from functions calls with C++ linkage.  The way to give them
C linkage type is to declare them extern "C".

Passing functions with C++ linkage type as GSignal callbacks works with
gcc/g++, but it is not guaranteed by the standard.

For more discussion you might want to read section 9.2.5 of TC++PL.

Chris

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list


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