Order of evaluation of function arguments

K

Kenneth Brody

Keith said:
The FAQ doesn't directly address this. Question 3.2 discusses
i++ * ++i, but it doesn't explicitly mention modifying the same
variable twice in different arguments of the same function call.
Combine this with the common misconception that the commas separating
arguments are comma operators, and the confusion is understandable.

It would be good for question 3.2 to mention function arguments. On
the other hand, I see that <http://www.eskimo.com/~scs/C-faq/q3.2.html>
celebrated its tenth birthday two months ago (that's ten years since
the page has been modified).

Perhaps simply modifying 3.8 to include:

Note that, although the comma operator is a sequence point, the
comma used to separate function parameters is not the comma
operator, and therefore is not a sequence point.

Of course, to confuse things, one could combine the comma operator
with the comma separator:

printf("%d, %d, %d\n", i, (j++, j++), k);

Is this guaranteed to increment j twice, passing the singly-imcremented
value to printf?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Keith Thompson

Kenneth Brody said:
Of course, to confuse things, one could combine the comma operator
with the comma separator:

printf("%d, %d, %d\n", i, (j++, j++), k);

Is this guaranteed to increment j twice, passing the singly-imcremented
value to printf?

Yes.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top