So, it looks like val++ is evaluated before the two other parameters. Can anybody tell why???
And what is the order in which parameters are evaluated(passed) to a function in General?
Also if we modify the printf as the following:
printf("%d %d %d", val, val++, val);
it causes a compilation error(warning). Again, why?
b) The interview question I've seen in the web: "What is the parameter passing mechanism to macros called?"
I would answer: "There is no one. Variables passed to the macros are just substituted while resolving macros at compile time"
c) Can anybody give link to a good article about parameter passing mechanisms (C-style, Pascal-style ... more?)
a) The order of evaluation is not defined. It could be whatever the compiler finds best.
b) Sounds right.
c) A related thing is http://en.wikipedia.org/wiki/X86_calling_conventions although it's about asm mostly. I'm not sure what you want to know.
I think you are asking about sequence points. Some languages are pretty specific about the order in which arguments to a routine are evaluated; C and C++ is not -- the compiler has liberty to choose the order in which arguments are evaluated before invoking a function (be sure to read up on sequence points).
The trick is that you are playing with your example is that you are playing with one of the nebular regions of C and C++, because the syntax for passing function arguments looks like other language elements, but each argument is, in fact, individually evaluated. Just when the compiler implements the increment is not exactly defined in relation to the other subexpressions.
The answer is that you really shouldn't write code like that.
OK, I've got your point, guys.
In the Sequence Points there is completely the same stated.
BUT
This question was told to be at sometime in the job test at the company I will may be attending:)
And when trying at codepad.org - it shows the stable result.
So it looks, like a pointers are always evaluated after just simple int++ and even somebody knows about it:)