Re: Is it a good thing that program mix C and C++?
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Thu, 29 Mar 2007 12:25:44 +1200
CBFalconer wrote:
Ian Collins wrote:extern "C" linkage suppresses name mangling for functions compiled as
CBFalconer wrote:
Ian Collins wrote:> >
CBFalconer wrote:
dolphin wrote:
Is it a good thing that program mix C and C++?
Mix, no. You can call C routines from C++, but not the reverse.
No so, C++ provides a mechanism (the extern "C" linkage specifier)
to make C++ functions callable from C.
That makes C callable from C++. Not the reverse.
It's a two way street.
No it isn't. The C++ compiler does various unspeakable things to
the function names in order to handle overloading, i.e. it creates
multiple names for functions depending on the types of their
parameters. It calls these functions with similarly adorned
names. This is all necessary to make C++ work. A C header file
can conditionally (on __cplusplus) include the extern "C" { .... }
wrapper on the function prototypes, which tells the C++ compiler
that these calls are unadorned. Now the linker can work.
C++. The rules of C++ permit only one instance of any extern "C"
function name, they can not be overloaded and they can be called from C.
Since the C++ object code uses those adorned names, the C compiler
has no way of generating calls to them.
It dose if they are declared extern "C" because the functions are not
mangled.
--
Ian Collins.
.
- References:
- Is it a good thing that program mix C and C++?
- From: dolphin
- Re: Is it a good thing that program mix C and C++?
- From: CBFalconer
- Re: Is it a good thing that program mix C and C++?
- From: Ian Collins
- Re: Is it a good thing that program mix C and C++?
- From: CBFalconer
- Re: Is it a good thing that program mix C and C++?
- From: Ian Collins
- Re: Is it a good thing that program mix C and C++?
- From: CBFalconer
- Is it a good thing that program mix C and C++?
- Prev by Date: Re: Learning C?
- Next by Date: Re: how to quit
- Previous by thread: Re: Is it a good thing that program mix C and C++?
- Next by thread: Re: Is it a good thing that program mix C and C++?
- Index(es):
Relevant Pages
|