Re: Is it a good thing that program mix C and C++?



CBFalconer wrote:
Ian Collins wrote:

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.

extern "C" linkage suppresses name mangling for functions compiled as
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.
.



Relevant Pages

  • Re: Overrides and mybase ??
    ... Yes this is known as overloading. ... Yes the compiler looks at the number of parameters & their types to decide ... The signatures of the methods (routines) need to be unique on number & type ... |>> calling the base classes default constructor. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Is it a good thing that program mix C and C++?
    ... You can call C routines from C++, but not the reverse. ... The C++ compiler does various unspeakable things to ... Since the C++ object code uses those adorned names, ...
    (comp.lang.c)
  • Re: Object-oriented programing (was Re: How old is the average Fortran programmer?)
    ... adjusting a few parameters by means of a curve fitting program. ... reverse communication, you can avoid monkeying with the original program. ... these reverse-communication routines in the past, ...
    (comp.lang.fortran)
  • Re: Reverse strings
    ... Your prototype for reverse says that the parameter is of type ... This will be automatically converted by the compiler to ... type char(*)[SIZE], that is pointer to array of SIZE char. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways
    ... but the disadvantage of the extra traversal for the REVERSE ... just out of curiosity (and possibly in bad form for replying to my own ... it strikes me that a clever compiler could unroll that, ... Well, first of all, the compiler would have to have some way of making ...
    (comp.lang.lisp)