用C前pression评估顺序 [英] Order of expression evaluation in C
问题描述
如果我有以下的前pression:
If I have the following expression:
c = (a) * (b)
什么是C90标准说的SUBEX pression'a'和'B'?
What does the C90 standard say about the order evaluation of the subexpression 'a' and 'b'?
推荐答案
有没有特别的顺序,因为乘法运算符是不是一个序列点。序列点包括逗号操作符,一个完整的前pression结束后,和函数调用。因此,评估顺序(A)
和(二)
要由编译器实现。因此,你不应该试图-做的东西(一)
,将有要在待观察副作用(二)
为了产生有效的结果。
There is no specified order since the multiplication operator is not a sequence point. Sequence points include the comma operator, the end of a full expression, and function calls. Thus the order of evaluation of (a)
and (b)
is up to the compiler implementation. Therefore you shouldn't attempt to-do something in (a)
that would have a side-effect that you want to be seen in (b)
in order to generate a valid result.
例如:
int a=5;
int b = (a++) * (a++); //<== Don't do this!!
如果您想为C序列点,全上市,你可以检查出一个更深入的参考。
If you want a full-listing of sequence points for C, you can check out a more thorough reference here.
这篇关于用C前pression评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!