Re: extern "C"
On Sep 5, 4:52 am, "northern_RATT" <n...@none.net> wrote:
<snip>> I need to be able to mix C and C++.
The main program is written in C and needs to access C++
code. To be more specific it's a user defined function in
fluent, but this should not be relevant.
I've allready read that i need to use the extern "C"
construction but i don't seem to be doing it right.
OK. Pardon a rank amature who only lurks here, BUT....
This looks like backwards logic to me. I thought that
'extern C' is a way for C++ code to call undecorated C code(?)
No. 'extern "C"' tells the compiler to use C linkage, period.
A C++ function can be declared 'extern "C"', in which case, it
uses C linkage (but is C++ in every other way), and can be
called from a C program.
The classical example is the function passed to things like
pthread_create (Unix) or CreateThread (Windows); since this
function is called from C code, it must be 'extern "C"'.
Not the otherway around!
Not that I have ever needed to face this, but I thought that C
calling C++ code needs some type of wrapper?
And how would you implement the wrapper? If you can't call C++
from C, you can't implement it in C, and if you implement it in
C++, you couldn't call it from C.
Typically, C++ code does require a wrapper, because it is using
argument types which C can't handle; the wrapper takes care of
any necessary type conversions. But thw wrapper itself is also
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34