473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

What is the different between c++ call convention and c call
convention?Can some give some examples?
Dec 7 '07 #1
2 2381
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
Dec 7 '07 #2
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
behavior.
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*********@gmail.com
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Jon Perez | last post by:
I saw this code snippet: sock.listen(20) for _ in range(20): newsock, client_addr = sock.accept() print "Client connected:", client_addr data = "" why use _ for this example? Is there any...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
32
by: Conrad Weyns | last post by:
I have recently gone back to doing some work in c, after years of c++, but I find the lack of templates and in particular the container in the stl to be a huge show stopper. There are math libs,...
15
by: Daniel Rudy | last post by:
What is the difference between packed and unpacked structs? -- Daniel Rudy Email address has been base64 encoded to reduce spam Decode email address using b64decode or uudecode -m Why...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
8
by: clintonG | last post by:
Every single time neophytes or converts ask about naming and style conventions what are they told by the majority consensus? The answer is "do what you prefer but do so consistently" right? Yes,...
50
by: LaundroMat | last post by:
Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to...
9
by: qglyirnyfgfo | last post by:
I was reading an article regarding .Net arrays and on that article, the author mentioned something about SZ arrays. As far as I can tell, SZ arrays are one dimension arrays that are zero based,...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.