Re: C/C++ calling convention
On Aug 25, 3:50 am, "BGB / cr88192" <cr88...@hotmail.com> wrote:
"Ian Collins" <ian-n...@hotmail.com> wrote in message
news:8dir1pF1saU13@mid.individual.net...
On 08/25/10 08:56 AM, Stanislaw Findeisen wrote:
Given an architecture and a language (C or C++), is there any standard
function calling convention? Or is it compiler dependent?
The two languages are different. With C, there will be a platform
standard, with C++ it is still (regrettably) compiler specific.
yep...
however, typically, C++ uses the same basic calling convention as C, but
usually differing only in that the C++ case tends to use a name-mangling
scheme (often compiler specific, but some "de-facto" conventions exist, for
example the use of MSVC-like conventions on Windows and the IA-64 ABI
name-mangling on Linux).
How can it? Things like the layout of the vtable are part of
the calling conventions, and C++ can't possibly use the same
ones as C here.
there does tend to be a difference in how compilers pass
'this', with some compilers using an additional register
(thiscall in MSVC), but more commonly it is passed as a hidden
first argument (although AFAIK usually after the hidden first
argument used for returning structs).
Except on Intel, the first argument *is* usually in a register.
although, it is not really "safe" to rely on the specifics of
any of this...
similarly, it is not really "safe" to use C++-based APIs
across library boundaries, nor for that matter to pass memory
or file references between DLL's (this leads to "fun"
sometimes...).
That's not true, and I've done it on many platforms.
for example, MSVC likes giving each DLL its own local C library,
MSVC does what you tell it in this regard. If you tell it to
give each DLL its own local C library, when you don't want to,
it's nobody's fault but your own.
and hence, its own local memory heap and set of open files,
resulting in a few issues which may pop up occassionally...
(these issues don't tend to pop up with MinGW or Cygwin, as
these handle this situation differently...).
I don't know about MinGW or Cygwin, but under most Unix, it's
also possible to arrange things so that each shared object has
its own free space arena as well, if this is what you want.
--
James Kanze