哪里来自顺序点? [英] Where do sequence points come from?

查看:128
本文介绍了哪里来自顺序点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,写东西像

++a = a++;

不仅是不可读的,而且违反了C / C ++程序百分点。

Is not only unreadable but also violates the c/c++ sequence points.

在哪里这些限制从何而来?如何才能找到他们的错误之前看到的那些问题?

Where do these limitations come from? How can one see those 'problems' before finding them as bugs?

推荐答案

基本上没有每个语句之间的C ++ 03的序列点。欲了解更多信息,请参阅 SO C ++ FAQ 。对于更多的信息做参考C ++标准,并牢记,在C ++ 11标准序列点用的测序替换之前的和的测序后的关系。

Basically there is a C++03 sequence point between each statement. For more information see the SO C++ FAQ. For even more information do consult the C++ standard, and keep in mind that in the C++11 standard sequence points were replaced with sequenced before and sequenced after relations.

要避免出现问题,根本就没有尝试是太聪明关于每个EX pression做了很多。

To avoid problems, simply don't try to be too clever about doing a lot in each expression.

不要试图做编译器的工作:留给编译器。你的任务是写code,其他人可以很容易理解,即清除code 。多次更新和不必要的使用有副作用的运营商是不与兼容。

Don't try to do the compiler's job: leave that to the compiler. Your job is to write code that other humans can easily understand, i.e. clear code. Multiple updates and needless use of operators with side effects is not compatible with that.

提示:洒常量几乎无处不在可能的

Tip: sprinkle const just about everywhere possible.

这限制了可能的状态改变,一个读者必须考虑到的。

That constrains the possible state changes that a reader must take into account.

这篇关于哪里来自顺序点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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