function calling conventions in C++

P

Pallav singh

Hi All ,

is there a function calling conventions in C++ , which specifies
Argument Passing left to right .

Thanks
Pallav Singh
 
S

SG

is there a function calling conventions in C++ , which specifies
Argument Passing        left to right .

As far as I know the C++ standard doesn't specify anything in this
regard except "language linkage" (extern "C" etc). Anything besides
that is probably implementation-specific. You could call "__declspec"
a quasi standard, though. The MinGW compiler seems to be mostly
compatible to Microsoft's in this regard.

Cheers!
SG
 
K

karthik.moc

As far as I know the C++ standard doesn't specify anything in this
regard except "language linkage" (extern "C" etc). Anything besides
that is probably implementation-specific. You could call "__declspec"
a quasi standard, though. The MinGW compiler seems to be mostly
compatible to Microsoft's in this regard.

Cheers!
SG

Hi,

Passing arguments is related with pushing arguments into the stack.
You know that Stack will grow downwards.

Let us assume 32 bit machine for the below discussion.

During a function call execution, BP points to the memory region which
is 8 bytes below the first argument. So, BP + 8 + i * 4 will point to
"i"th argument. In order to provide this facility, normally arguments
will be pushed from last to first argument.

This is no way related to calling conventions. Calling conventions
mainly deals with stack unwinding process during "return" from a
function call. _fastcall makes some registers to hold arguments also.
But no calling convention explicitly defines the order of pushing
arguments into the stack.

Thanks & Regards,
Karthik.
 
J

James Kanze

No. There's not even a guarantee that there is an order in the
evaluation---the compiler can interleave the evaluation of
different arguments (and likely will on a modern processor, in
order to avoid pipeline stall).
Passing arguments is related with pushing arguments into the
stack. You know that Stack will grow downwards.

On a modern processor with a lot of registers, the first n
arguments will generally be passed in registers, not on the
stack. And of course, the stack may grow up or down, depending
on the processor.
Let us assume 32 bit machine for the below discussion.
During a function call execution, BP points to the memory
region which is 8 bytes below the first argument.

The only BP I know is a register on 16 bit Intel processors. On
32 bit Intel, there's a register EBP, but on other processors,
there's generally nothing by this name.
So, BP + 8 + i * 4 will point to "i"th argument. In order to
provide this facility, normally arguments will be pushed from
last to first argument.

Maybe. That's a convention for a specific ABI; it's certainly
not universal.
This is no way related to calling conventions. Calling conventions
mainly deals with stack unwinding process during "return" from a
function call.

Calling conventions deal with *everything* which is involved in
the call. The fact that the first five arguments are placed in
registers o0 to o5 on a Sparc, for example. The fact that the
this pointer is passed as if it were an additional first
argument. The fact that the called function must save certain
registers (or not).
_fastcall makes some registers to hold arguments also. But no
calling convention explicitly defines the order of pushing
arguments into the stack.

Every calling convention defines how the arguments are to be
passed. In practice, on older architectures, like Intel, with
very few registers, most arguments will be passed on the stack;
depending on the architecture, there isn't always a large choice
of reasonable solutions, so all implementations tend to use the
same conventions (more or less), but there's no requirement for
this, and I've seen different conventions for the same processor
many times.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top