0
Follow
0
View

C | about C language function

beloved840426 注册会员
2023-02-27 17:09

It is recommended to look at the inverse pool encoding. The
VC++ environment computes all the arguments of a function before loading the function.
So the above equation is equivalent to:
i+=3;
i-=2;
fun(i, i);

cz42202046 注册会员
2023-02-27 17:09

If fun(i+3,i-2), the values of both expressions are first cached in temporary storage and passed as arguments to fun
If fun(i+=3,i-=2), The first assignment is done, the result of the expression is actually i itself, and the final execution is fun(i,i)

dongkai0919 注册会员
2023-02-27 17:09

Then why distinguish between function arguments evaluated from left to right and from right to left?

duron571 注册会员
2023-02-27 17:09

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > in the vc + + environment, according to the operation rules of c + +, the function parameter order is uncertain. Thus, in fun(i+=3, i-=2), the order of execution of i+=3 and i-=2 is indeterminate. Some compilers may execute i+=3 first, others may execute i-=2 first.

Suppose the compiler executes i+=3 and then i-=2, the following process would occur:

1, i+=3 is equivalent to i=i+3, that is, add the value of i to 3, then the value of i is 11.
2, i-=2 is equivalent to i=i-2, that is, subtract 2 from the value of i, and then the value of i is 9.
3, fun(i+=3, i-=2) is equivalent to fun(11, 9), that is, 11 and 9 are passed to the function as arguments.
So if the compiler executes i+=3 and then i-=2, it gets fun(11, 9).

If the compiler executes i-=2 and then i+=3, it gets fun(9, 10).

In summary, the result of the function call fun(i+=3, i-=2) may vary depending on the order in which the compiler evaluates the arguments.

flashgirl_xm 注册会员
2023-02-27 17:09

It evaluates the entire assignment statement before passing i as an argument to fun. i is equal to 9, so both arguments are 9

About the Author

Question Info

Publish Time
2023-02-27 17:09
Update Time
2023-02-27 17:09

Related Question