用C前pression评估顺序 [英] Order of expression evaluation in C

查看:98
本文介绍了用C前pression评估顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下的前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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆