Hi,
Is it safe (or possible) to write modules in C++ instead of C? I don't any C++-safe declarations (extern "C") in Pike headers, so it seems - not... Do I miss something or? Regards, /Al
Should be possible if you just do
extern "C" { #include "whatever.h" }
Make sure to not throw any C++ exceptions though.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-02-17 11:00: Subject: modules in C++?
Hi,
Is it safe (or possible) to write modules in C++ instead of C?
I don't any C++-safe declarations (extern "C") in Pike headers, so it seems - not... Do I miss something or?
Regards, /Al
/ Brevbäraren
On Tue, Feb 17, 2004 at 11:05:03AM +0100, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
Should be possible if you just do
extern "C" { #include "whatever.h" }
Not sure... Some headers (due to structure) cannot be "wrapped" like this, unfortunately (especially if some of them already use extern "C" - and this is true because system and standard libraries do).
Make sure to not throw any C++ exceptions though.
It won't harm (unless incorrectly handled) - C++ runtime is active only during "lifetime" of C++ code. At least, I've experience mixing C/C++ and there are no problems with exceptions...
Regards, /Al
On Tue, Feb 17, 2004 at 11:05:03AM +0100, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
extern "C" { #include "whatever.h" }
Make sure to not throw any C++ exceptions though.
There is another problem, which might clash with C++ exception handling (and possibly others).
Pike_error() uses longjmp(), which is not recommended to be used in C++ runtime... And this is, IMHO, unavoidable...
Regards, /Al
Just don't call Pike_error() from a function with C++ linkage (either directly or indirectly) and you should be fine, I think. I.e. do
extern "C" void f_foo(INT32 args) { /* Process arguments using only "C" code */
/* Call C++ code, which does not used any pike functions */
/* Convert result to Pike datatypes using "C" code, possibly calling Pike_error() */ }
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-02-27 12:52: Subject: Re: modules in C++?
On Tue, Feb 17, 2004 at 11:05:03AM +0100, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
extern "C" { #include "whatever.h" }
Make sure to not throw any C++ exceptions though.
There is another problem, which might clash with C++ exception handling (and possibly others).
Pike_error() uses longjmp(), which is not recommended to be used in C++ runtime... And this is, IMHO, unavoidable...
Regards, /Al
/ Brevbäraren
pike-devel@lists.lysator.liu.se