- 论坛徽章:
- 5
|
本帖最后由 starwing83 于 2012-05-28 23:28 编辑
回复 19# wwwsq
An assignment operator stores a value in the object designated by the left operand. An
assignment expression has the value of the left operand after the assignment, but is not an
lvalue. The type of an assignment expression is the type of the left operand unless the
left operand has qualified type, in which case it is the unqualified version of the type of
the left operand. The side effect of updating the stored value of the left operand shall
occur between the previous and the next sequence point
摘自ISO C。
注意,我标红了这段话的第一个after,注意你的MSDN里面也是有个after的。after如何理解?是说的时间?非也。注意最后一段加粗的话。如果after指的是时间,那么这段话明显和after矛盾了。那么after指的是什么呢?是赋值运算结果(是的,标准规定赋值运算是有返回结果的!)的类型和值等等。即你可以当作那个值是赋值后的左操作数的值,这时赋值其实可以还没完成。比如说,我先算值,然后返回这个值进行某些操作(比如比较),最后再进行实际的保存。
对于操作的类型,下面这段代码:
int a;
float b = 1;
printf("%s\n", typeof((a = b)));
(假设有typeof函数的话)的结果应该是int,而不是float。仅此而已。而且后面对这个类型也值了更严格的限制:如果右操作数是非限定版本,则类型应该是非限定版本(去掉了const、volatile等等以后的版本)。这么说你理解了?
抓错没事儿,把对的抓成错的就贻笑大方了…… |
|