C'S前pression和C ++的前夫pression区别 [英] difference between c's expression and c++'s expression

查看:117
本文介绍了C'S前pression和C ++的前夫pression区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()
{
   int i=3;
   (++i)++;        
   printf("%d",i);
}

此方案适用于G ++编译器,但不是GCC。
如果我写我++++或++我++它不工作CPP还。
我认为这是C-EX pression和c ++的区别 - 前pression。
关于L值和R值有人可以解释一下吗?

This programs works with g++ compiler but not gcc. If i write i++++ or ++i++ it doesn't work in cpp also. I think there is difference between c-expression and c++-expression. Can somebody explain about L-value and R-value ?

推荐答案

编辑:这个答案是不正确的更新问题,它适用于原来规定的问题

(我++)++ 不应该与任何海湾合作委员会或g工作++,不管他们是否在两种语言后缀增量解析该文件为C或C ++需要的左值的作为操作数,结果是右值的。

(i++)++ shouldn't work with either gcc or g++, whether or not they are parsing the file as C or C++ in both languages postfix increment requires an lvalue as an operand and the result is an rvalue.

(请注意,右值的只用于正式在C ++中,在C前pressions的结果要么是明确的左值的或他们只是没有的左值的这个术语的右值的不是C标准的规范文本使用的。)

(Note that rvalue is only used formally in C++. In C the results of expressions are either explicitly lvalues or they're just not lvalues. The term rvalue isn't used in the normative text of the C standard at all.)

Simplisticly,一个的左值的是前pression指向一个对象,即概念的存储区域的某个地方。可修改的左值的是什么,它​​是有效的分配到这样可以在出现的的转让前pression的右手边。

Simplisticly, an lvalue is an expression that refers to an object, i.e. conceptually a region of storage somewhere. A modifiable lvalue is something that it is valid to assign to so can appear on the left hand side of an assignment expression.

这是右值的仅仅是一个值,东西,你可以指定一个可修改的左值的距离,而不是东西,你可以分配给。它只能出现在赋值前pression的的右键的一面。

An rvalue is just a value, something that you can assign a modifiable lvalue from, but not something that you can assign to. It can only appear on the right side of an assignment expression.

G ++ 给我的错误:左值要求作为增量的操作数

preFIX增量(和递减)略有不同。在C ++中的preFIX增量的结果是一个明确的左值的(5.3.2 / 1 [EXPR pre.incr。]);用C是明确不是的左值的(6.5.3.1指出++ E是等于(E + = 1); 6.5.16说,任何分配的结果不是左值)。

Prefix increment (and decrement) are slightly different. In C++ the result of a prefix increment is explicitly an lvalue (5.3.2/1 [expr.pre.incr]); in C it is explicitly not an lvalue (6.5.3.1 states that ++E is equivalent to (E+=1); 6.5.16 says that the result of any assignment is not an lvalue).

(++ I)++ ,因此,只有在C ++语义正确,但它拥有的未定义行为的,因为你是一个存储值的对象两次中间没有其他的序列点

(++i)++ is, therefore, semantically correct only in C++, however it has undefined behaviour because you are storing a value to an object twice without an intervening sequence point.

这篇关于C'S前pression和C ++的前夫pression区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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