广嵌科技  广嵌教育  English  
 
首页 > 软件开发 > C/C++ > C和C++里面的lvalue 和 rvalue的释义
C和C++里面的lvalue 和 rvalue的释义
来源:赛迪网  作者: 时间:2008-04-17 发布人:华女
  在看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的属性,和左右根本没有任何关系。

·上一条:离子迁移谱仪嵌入式系统的设计
·下一条:C++对象布局及多态实现之动态和强制转换

评论
发布者 标题 发布日期
暂没有任何评论
以下发言只是广嵌网会员个人意见,非本网立场 查看更多评论

发表评论
·尊重网上道德,遵守中华人民共和国的各项有关法律法规。
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任。
·本站管理人员有权保留或删除其管辖留言中的任意内容,本站有权在网站内转载或引用您的评论。
·参与本评论即表明您已经阅读并接受上述条款。
标题:
发布者:
内容:
验证码:

相关信息
·.Net(C#)开发漫谈..
·.Net(C#)开发漫谈..
·C#编程实用技巧:轻松实..
·学生管理系统(C原代码)
·嵌入式智能人机界面与PL..
·嵌入式系统编程中的代码优..
·C++对象布局及多态实现..
·C和C++里面的lval..
·C语言平台缩短SoC前期..
·用Visual C++实..
Copyright ©2005-2007 广东省嵌入式软件公共技术中心.All Rights Reserved.版权所有 复制必究
客户服务支持:020-32068395-832 24小时服务热线:13631411558
技术支持与报障:gdesc@midea.com.cn 020-32068395-807/809
粤ICP备05104135号