Re: C/C++ calling convention
On Aug 25, 2:39 pm, Goran Pusic <gor...@cse-semaphore.com> wrote:
On Aug 25, 3:25 pm, James Kanze <james.ka...@gmail.com> wrote:
On Aug 25, 11:28 am, Goran Pusic <gor...@cse-semaphore.com> wrote:
On Aug 25, 9:42 am, Stanis=B3aw Findeisen <nore...@eisenbits.com> wro=
te:
[...]
I'd say that for a given compiler (version) on a given
platform, there's no difference between a C and a C++
function, except that you need extern "C" to turn off name
mangling that happens with a C++ compiler. So that's why
you have extern "C".
And you'd be wrong. At least one compiler I've used used
different calling conventions for C and for C++.
Ugh. Which one and why (if you can be bothered)?
The old Zortech compler. Because C is more broken than C++:-).
Intel has hardware support for cleaning up the stack, provided
the function in question has a fixed number of bytes as
arguments. In pre-standard C, it was usual to call functions
like printf without a declaration in scope, so the compiler had
to assume that all functions were varargs (and thus used the
less efficient convention). C++ has always requires a function
declaration to be in scope in order to call the function, so the
compiler used the hardware support to clean up the stack. (The
results were slightly smaller and slightly faster.)
To be honest, I can't think of a reason why would any compiler
match calling conventions betwen C and C++, but that seems a
most reasonable (only sensible, really) thing to do when using
extern "C".
When a function is declared ``extern "C"'', it must match the
calling conventions of C.
--
James Kanze