j+++i这个表达式的,根据C标准 "the behavior is undefined"
也就是说这是个错误的程序,编译器给出任何结果都可以。
原因是:一个对象在两个顺序点(sequence point)之间只能读写一次。
j++产生一次写j,同时j+++i又有一次读j(并且读出的数据并不是用来改变j的值)这违反了C表达式的限制。
delimy 发表于 2010-10-01 17:04
Furthermore, the prior value shall be accessed only to determine the value to be stored.
And that's what the second sentence says: if an object is written to within a full expression, any and all accesses to it within the same expression must be directly involved in the computation of the value to be written
a full expression is an expression statement, or any other expression which is not a subexpression within any larger expression
full expression
The complete expression that forms an expression statement, or one of the controlling expressions of an if, switch, while, for, or do/while statement, or the expression in an initializer or a return statement. A full expression is not part of a larger expression. (See ANSI Sec. 3.6 or ISO Sec. 6.6.)
Afull expression is an expression that is not part of another expression or of a declarator.
Each of the following is a full expression: an initializer; the expression in an expression
statement; the controlling expression of a selection statement (if or switch); the
controlling expression of a while or do statement; each of the (optional) expressions of
a for statement; the (optional) expression in a return statement. The end of a full
expression is a sequence point.
我觉得程序员恰恰应该摆脱“按一般的人类的思维”
如果是写code,必须事先知道自己要写什么
如果是读code,正确的方式应该是编译器方式。因为程序设计语言不是自然语言,而是一种严格的形式语言
至于您说的多线程,我还没想通您想表达的是什么意思。能否麻烦更具体地说说么
KBTiller 发表于 2010-09-30 20:53
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |