On 02/20/2011 03:14 AM, Per Jessen wrote:
I was thinking that the compiler clearly knows how many arguments is puts on the stack, so perhaps that number was also pushed on the stack.
Certainly it is the compiler that sets up the stack. As others have
said, the implementation has a calling convention. On the DEC Alpha, the
first 6 parameters were placed into registers with the rest of the
parameters (if any) on the stack. HP PA-RISC had a similar calling
convention. Whether arguments are in registers or on the stack, C
defines the behavior.
The order in which parameters are placed on the stack or in registers is
different in C than in other languages because C (and C++) allows for a
variable number of parameters. While the compiler knows how many
arguments it pushed onto the stack when calling a function, it does not
really know how many arguments are actually on the stack in the called
function. In some implementations, there is also a stack frame register
that makes it easier to unroll the stack. But there are also other
things stored in the stack, such as saved registers. But in general,
there is no tag on the stack that indicates the number of parameters.
--
Jerry Feldman