By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,279 Members | 2,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,279 IT Pros & Developers. It's quick & easy.

What is the different between c++ call convention and c callconvention?

P: n/a
What is the different between c++ call convention and c call
convention?Can some give some examples?
Dec 7 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
On Thu, 6 Dec 2007 19:25:57 -0800 (PST), dolphin <jd*******>
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" 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); 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); 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

Jack Klein
Home: http://JK-Technology.Com
FAQs for
Dec 7 '07 #2

P: n/a
On Dec 7, 5:30 pm, terminator <farid.mehr...@gmail.comwrote:
On Dec 7, 5:56 pm, James Kanze <james.ka...@gmail.comwrote:
On a Sparc, of course, the way the hardware supports function
calls really only leaves one possible convention, so there is no
practical difference between the calling conventions of C and of
C++, except name mangling. On an Intel, it depends; it depends.
I've seen several different conventions, and Microsoft seems to
use some non-standard extensions to support them. I don't know
the defaults, but it does work.
You are missing the fundamental difference between C and C++:
incompleted structured programmimng style versus object
oriented programming style.
I don't think so. When I wrote C, it was completely structured
(and even a little OO). And my C++ style is very OO. (At least
my C++ at the application level.
In C you had no concept as construction and destruction,
And how is that relevant here? (Or to your previous phrase?)
therefore a function with C linkage (calling convention) often
does not call the destructor for its arguments(stack clean up
is more descriptive) and the chore is left to the caller, OTH
a function with C++ linkage is responsible for the destruction
of its arguments and leads to shorter overall code size.
You're confusing issues. We're talking here about the very low
level argument passing---the machine code level, in fact.
Obviously, C linkage or not, you can't pass a non-POD type by
value to C code. More generally, when passing between two
different languages, you have to map the types, and in some
cases, there will be no appropriate mapping.

The difference between C and C++, here, is that C++ has always
required a function prototype to be in scope, and doesn't allow
extra arguments (which are ignored). Officially, the rules in C
are not that different, and extra arguments are also forbidden.
But in C, this was an innovation by the C committee---most
earlier compiler would allow you to call e.g. printf without
having included <stdio.h>, and even today, most C compilers will
want to support this, even if the standard says it is undefined
The difference is similar to that of the 'exit' and 'throw'.
You've lost me there? Exit and throw are two quite different
and unrelated mechanisms. What do either have to do with
function calling conventions, though?

James Kanze (GABI Software) email:ja*********
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.