I was reading this excerpt from the GNU C manual:
You use the comma operator, to separate two (ostensibly related) expressions.
Later in the description:
If you want to use the comma operator in a function argument, you need to put parentheses around it. That’s because commas in a function argument list have a different meaning: they separate arguments.
Until now, everything is alright. The weird part is:
foo (x, (y=47, x), z);
is a function call with just three arguments. (The second argument is(y=47, x)
.)
The question is: how is the parameter pushed on the stack, how do I access it from within the function?
In your case,
foo (x, (y=47, x), z);
is functionally similar as
foo (x, x, z);
As per the property of comma operator, the LHS operand is evaluated and the result is discarded, then the RHS operand is evaluated and that's the result.
For sake of completion, quoting the C11
, chapter §6.5.17
The left operand of a comma operator is evaluated as a void expression; there is a sequence point between its evaluation and that of the right operand. Then the right operand is evaluated; the result has its type and value.
Point to note: the variable y
will be updated, as the LHS operand is evaluated as a void expression, but has no effect on this funcion call. In case, the y
is a global variable and used in foo()
function, it will see an initial value of 47
.
That said, to answer
how is the parameter pushed on the stack
is very very implementation (architecture) dependent. C does not specify any order for function argument passing and some architecture may event not use "stack" for function argument passing, at all!!