Http://sunxiunan.com /? P = 1742
Browse Q. yuyun's blogArticleHttp://www.rainsts.com/article.asp? Id = 959 I found a small problem. It is estimated that some people with similar ideas also have one. So record it.
The problem is that:
"Obviously, according to The cdecl rule," printf (..., The printf function parameters in test (2), test (1) "are sequentially set from right to left (this statement is used for the moment ). Therefore, test (1) is called first, and then test (2). The above assemblyCodeThis is also explained ."
Despite the fact, this is a question.
The cdecl inbound order is correct. The inbound order is for the expression results separated by commas. That is to say, each result must be in this order. However, the order of expression calculation (or the call of each function separated by commas) is not specified. The last section on page 52 of K & R photoprinting plate is very clear. The following F and G may not be called first:
C, like most versions ages, does not specify the order in which the operands of an operator are evaluated. (exceptions are & |? : And ",") for example X = F () + g ();
Start on page 63:
The commas that separate function arguments, variables in declarations, Etc., are not comma operators, and do not guarantee left to right evaluation.
This means that the comma-separated function parameters are different from the comma operator, and the order of calculation from left to right is not guaranteed (or from right to left, of course ).
Note that this evaluation is actually a call to test (2) and test (1. If these calls have boundary effects, different results may be obtained in different compilers and operating systems. Another similar problem is that the same variable is called more than twice in the parameter list.
If you want to ensure the order of value (note that it is not the order of the result), you can only use a temporary variable to save the call results, or use a comma to operate, & | this ensures the order of values.
In fact, I have mentioned this issue in my previous blog, but I can repeat it once again. Http://sunxiunan.com /? P = 1684
References:
Article 7 http://www.andromeda.com/people/ddyer/topten.html reference
C traps and defects 3.7 Value Order