On Sat, 24 Jun 2006 12:54:48 -0400, "Your Uncle"
<in*****@crippled.net> wrote in comp.lang.c++:
I'm given to understand that your standard is specific regarding linking to
c. Furthermore I'm going to speculate that there exists a c++ version of
Keith Thompson, brilliant, encyclopedic and able to confuse by giving me the
exact answer, all 42 volumes. I just want to know wrap a C function so that
I don't stomp all over it when I bring it down the hall. cheers, furunculus
The C++ language allows linkage specifications, of which it
specifically defines exactly one, extern "C". The intent is that such
functions should be compiled in such a way that they may be linked
with code compiled with a compatible C compiler, or perhaps call
system functions designed to be called from C. Note that the standard
neither requires nor guarantees that extern "C" will provide
compatibility with any particular C compiler or system call.
What extern "C" specifically does not do is make the C++ compiler
compile C code. The code is still treated by the compiler as C++
code. Only the linkage is changed.
That means that you can't compile C code with a C++ compiler and
extern "C" if it contains any of the many imcompatibilities between C
and C++.
This function cannot be compiler by a C++ compiler, regardless of
whether you try to give it C linkage:
void func()
{
int new; // reserved word used as variable name
double static_cast; // ditto
void *vp = 0;
int *ip = vp; // can't assign void* to object *
}
If you want to write code that can compile as C and also as C++ with C
linkage, you must restrict yourself to the common subset of C and C++.
In at least some cases, this results in code that is neither good C
nor good C++.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html