guile-user
[Top][All Lists]
Advanced

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

Re: Guile initialization and string evaluation with C++


From: Chris Vine
Subject: Re: Guile initialization and string evaluation with C++
Date: Wed, 2 Apr 2014 13:09:27 +0100

On Tue, 1 Apr 2014 15:34:50 +0200
Ralf Mattes <address@hidden> wrote:
[snip]
> I'd do this slightly different: instead of using a non-member
> function (which needs to be declared a friend) I'd rather give my
> object a static function - static functions _can_ be used as C
> callbacks (since they don't expect a hidden instance as the first
> parameter). You'd still need to pass down an instance of your
> GuileApplication class so it can be handed to scm_boot_guile as the
> data parameter. This is asdmittedly only slightly better than your
> solution. 

This will work with gcc but not with all compilers (in particular
not with some intel compilers). This is because static member functions
can only have C++ language linkage according to the C++ standard.  On
the other hand libguile functions taking function pointers expect
function pointers with C language linkage.  It so happens, as I say,
that gcc (and I think clang) adopt the same calling conventions for
static member functions and for C functions, but compilers are not
obliged to do this.  (Name mangling is not an issue with function
pointers, but the calling convention for argument passing and so forth
is.)

The only wholly portable approach is to go down the route suggested by
the OP, and to declare the friend function as having C language linkage
using extern "C".

The OP might get some more general ideas about implementation
approaches for mixing C++ with libguile from this:

http://cxx-gtk-utils.sourceforge.net/2.2/namespaceCgu_1_1Extension.html
http://cxx-gtk-utils.sourceforge.net/2.2/extension_8h_source.html

Chris



reply via email to

[Prev in Thread] Current Thread [Next in Thread]