| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2407 人关注过本帖
标题:左值到底该怎么理解?r-value和l-value是什么意思?
只看楼主 加入收藏
nevernormal
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-6-30
收藏
 问题点数:0 回复次数:3 
左值到底该怎么理解?r-value和l-value是什么意思?

RT,谢谢大虾

2007-07-01 23:12
百年不亮
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:789
专家分:0
注 册:2006-4-14
收藏
得分:0 
[QUOTE]

C和C++里面的lvalue 和 rvalue的释义

作者:nathanxu 来源:不详 (2006-07-11 17:31:48)

在看GCC的文档的时候,看到一个词lvalue,查了金山词霸其释义为 lvalue [计] 左值。因为的确在介绍编译原理的课程中听过这个词,大致知道其意思就没有多想。但是看完GCC文档的这个篇幅,都无法明白全篇在说什么。问题还是出在了lvalue这个词的“左值”是什么意思的理解上了。再找M-W字典,却告知没有这个词。于是google了一把,的确很多地方都称其为左值,我仍然不得要领。最后在一个百科网站About Site上找到该词的准确释义,摘贴如下:
Definition: C and C++ have the notion of lvalues and rvalues associated with variables and constants. The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.

Another view of these terms is that objects with an rvalue, namely a variable or a constant can appear on the right hand side of a statement. They have some data value that can be manipulated. Only objects with an lvalue, such as variable, can appear on the left hand side of a statement. An object must be addressable to store a value.

Here are two examples.

int x;

x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
// addressable. It cannot be a lvalue.

这段就说的很明白 lvalue中的l其实指的表示该值的存储地址属性,而另外一个相对的词rvalue值中的r指得是read的属性,和左右根本没有任何关系。

[/QUOTE]
2007-07-01 23:38
nevernormal
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-6-30
收藏
得分:0 
有点明白了,大虾辛苦了
2007-07-01 23:49
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
left/right - value ...有必要祭出词爹么?... 太敬业了..

女侠,约吗?
2007-07-01 23:52
快速回复:左值到底该怎么理解?r-value和l-value是什么意思?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020267 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved