On Thu, 6 Dec 2007 19:25:57 -0800 (PST), dolphin <jd*******@gmail.com>
wrote in comp.lang.c++:
What is the different between c++ call convention and c call
convention?Can some give some examples?
Neither C nor C++ define a "calling convention". Particular compilers
provide their own "calling conventions", generally based on the
underlying processor architecture and usually also on the operating
system that the code will run under.
If you are interested in the calling conventions for a particular
compiler on a particular, you need to ask in a newsgroup for that
particular compiler/platform combination.
On the other hand if you are talking about linkage, as when use:
extern "C"
....in a C++ program, that is defined by the C++ standard although the
details are compiler specific.
A C compiler can use a very simple linkage model, where the compiled
output from multiple source files is linked together with libraries.
That is because in C, any given external symbol can be defined once
and once only.
If you have a function:
int some_func(int);
....in a C source file, there can't be any other object with external
linkage using the symbol "some_func" in a program.
C++, on the other and, allows multiple functions to have the same
name, due to overloading:
int some_func(int);
double some_func(double);
long some_func(long);
....so it must somehow modify these names in the output files so the
linker can connect the right call to the right function.
If you define a function in a C++ program with extern "C", you tell
the C++ compiler to generate its linkage name the same way a
compatible C compiler would.
The intent, which is not actually guaranteed, that this allows you to
combine both C code (compiled with a C compiler) and C++ code into a
single program. Almost all C++ compilers also provide C compilers and
so this method works when the C++ and C code are compiled with the
same compiler.
As to how the C++ compiler generates unique external names for the
linker from different functions with the same name in your source
code, the details are left up to the individual compiler. The common
mechanism is referred to as "name mangling".
Again, if you want to know how a particular compiler does "name
mangling", you need to ask in a group supporting that particular
compiler.
--
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.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html