<an*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have an existing C++ library . Now i am another application using
this C++ lib.
The problem here is i want to call C++ fn. from C file .If i use an
extern "C"declaration for that fn. then the original calls to this fn
creates error . eg
tobeused.cc
writtenincpp(int i ,char c)
{
}
---------
Now this fun writtenincpp() is being called from other C++ files in
the
library.The compiler here does name mangling so other calls are
resolved (from c++ files)
But I want to call this fn. from a C file . so if i use
tobeused.cc
extern "C" void writtenincpp(int ,char)
writtenincpp(int i,char c)
{
}
----------------
The compiler now does not perform name mangling and this can now be
called successfully from C file .But the other refrences through C++
files generates an error.
So ,is there any means usingwhich i can have a fn. written in C++ file
which can be called from any C or C++ files (without changing anything
in other C++ files)
comp.lang.c++ is a better place to ask; comp.lang.c likes to pretend C++
doesn't exist. clc++ acknowledges C's existence.
<OT>
The library must have been compiled with the function declared as extern
"C"; that disables name-mangling. You can't just modify the header; you
have to recompile the library (and everything that depends on it).
If you compile the function without that, it will be mangled as normal,
and then your attempt to call it as extern "C" without name mangling
will result in a linker error.
You may find it easier to create a stub .cpp file which contains an
extern "C" function which then calls the native C++ function. This stub
function is what you'd need to call from C. Slower, but easier to do,
especially if you can't easily modify the library (and everything that
calls it from C++).
</OT>
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from
http://www.teranews.com