guile-user
[Top][All Lists]
Advanced

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

Re: Guile and C++


From: David Fang
Subject: Re: Guile and C++
Date: Tue, 18 May 2010 17:22:40 -0400 (EDT)

How would this work if I wanted to not run Guile embedded in a C++
program, but instead load the C++ code at runtime from a regular Guile
interpreter? (This could use either the libffi binding or the regular
Guile ones.)

Since Guile is written in C, formally according to the C++ standard, you can only load Guile from C++ code, and not the opposite. So main() must be C++.

GCC though has integrated C and C++ fully, it seems. So you can call C++ from C code, but the latter do not implement C++ exception stacks, and may not call C++ initialization function properly (I haven't checked). It means that throwing and catching exceptions within C++ functions called from C seems to work fine, but if one tries to pass it through a C function, the program will throw a terminate exception.

Hi,
FWIW, I've used guile with C++ both ways: calling the main REPL loop in libguile from a C++ main, and also by creating loadable modules in C++, and calling load-extension with an initialization function. Both work just fine, but you should be aware that guile errors do not unwind the stack on error, so C++ stack objects do not get destroyed in the event of exceptions/errors in the guile library. I usually write the initialization function in the extern "C" namespace to avoid symbol name mangilng. Also, global statics in C++ modules are initialized upon loading, from what I've seen.

Fang


David Fang
http://www.csl.cornell.edu/~fang/
http://www.achronix.com/




reply via email to

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