该贴子第一条回答虽然浅尝辄止,但还是很有参考价值。

https://www.quora.com/What-is-lvalue-and-rvalue-in-C

IBM一个简单的说法是:

“…通俗的左值的定义就是非临时对象,那些可以在多条语句中使用的对象。所有的变量都满足这个定义,在多条代码中都可以使用,都是左值。右值是指临时的对象,它们只在当前的语句中有效。”

https://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/index.html

可以这样理解,“非临时”意味着该值应该存储在系统的寄存器中,而“临时”意味着该值可以存储在内存或临时寄存器中。因为rvalue临时存在于内存中,对rvalue的取地址操作是没有稳定的结果的。

回到quora的回答。

变量是表象,真正有意义的是变量对应的地址。

对于某个变量对应的地址,如果往该地址存一个数值,这是lvalue,因为该值最终需要送到寄存器用于做后续运算;如果从该地址取一个值,这是rvalue,因为取出来的值会被临时存在内存或临时寄存器中。

The difference is when a variable is used as an lvalue, the compiler sets up the computer to store a value to the address in the pointer. When it's used as an rvalue, it tells the computer to load a value from the address in the pointer into a register in preparation for some other operation, like calling a function, or for an indexing operation (for use in an array), or an arithmetic computation.

注意该段文字专门强调了store和load这两个命令。

C中的lvalue和rvalue的更多相关文章

  1. [C++] Lvalue and Rvalue Reference

    Lvalue and Rvalue Reference int a = 10;// a is in stack int& ra = a; // 左值引用 int* && pa ...

  2. 移动语义 && 函数调用过程中的 lvalue

    当以一个函数内的临时变量对象作为另一个函数的形参的时候,原函数内的临时对象即 rvalue,就会成为此函数内的 lvalue. 这样会重新导致效率低下,因为造成了大量复制操作. <utility ...

  3. 理解C++ lvalue与rvalue

    一个众所周知的危险错误是,函数返回了一个局部变量的指针或引用.一旦函数栈被销毁,这个指针就成为了野指针,导致未定义行为.而左值(lvalue)和右值(rvalue)的概念,本质上,是理解“程序员可以放 ...

  4. 理解lvalue和rvalue

    今天看C++模板的资料,里面说到lvalue,rvalue的问题,这个问题以前也看到过,也查过相关资料,但是没有考虑得很深,只知道rvalue不能取地址,不能赋值等等一些规则.今天则突然有了更深层次的 ...

  5. L-value 和 R-value.

    An L-value is something that can appear on the left side of an equal sign, An R-value is something t ...

  6. C++98/11/17表达式类别

    目标 以下代码能否编译通过,能否按照期望运行?(点击展开) #include <utility> #include <type_traits> namespace cpp98 ...

  7. C++11中rvalue references的使用

    Rvalue references are a feature of C++ that was added with the C++11 standard. The syntax of an rval ...

  8. C++ lvalue(左值)和rvalue(右值)

    lvalue(左值)和rvalue(右值) 昨天写代码遇见一个这样的错误:{ "cannot bind non-const lvalue reference of type 'int& ...

  9. 左值 lvalue,右值 rvalue 和 移动语义 std::move

    参考文章: [1] 基础篇:lvalue,rvalue和move [2] 深入浅出 C++ 右值引用 [3] Modern CPP Tutorial [4] 右值引用与转移语义 刷 Leetcode ...

随机推荐

  1. RGB和十六进制转换

    1.十六进制换RGB 例:  var color = '#69ad52' let r = parseInt(“0px” + color.slice(1, 3))  //105 let g = pars ...

  2. Linux eth0, eth1, ..., eth%d 的生成【转】

    转自:https://blog.csdn.net/xiruanliuwei/article/details/78765255 一直很好奇,Linux下的eth0, eth1,eth2等是如何生成的~ ...

  3. U200-SNMP

    U200配置snmp snmp-agent sys-info version v2c snmp-agent community read jkzh snmp-agent trap enable snm ...

  4. 04-树5 Root of AVL Tree(25 分)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  5. linux c(一)Helloworld

    终端的屏幕上输入命令如下: 使用vi helloworld.c打开helloworld.c文件,写下如下代码:

  6. appium 链接真机

    1. 安装驱动 说明:如果驱动装不上,可以使用第三方的工具去安装.(一般来说还是用第三方) 这里推荐锤子科技的HandShaker, 地址:http://www.smartisan.com/apps/ ...

  7. java并发编程笔记(一)——并发编程简介

    java并发编程笔记(一)--简介 线程不安全的类示例 public class CountExample1 { // 请求总数 public static int clientTotal = 500 ...

  8. WebX.0:Web1.0

    ylbtech-WebX.0:Web1.0 web1.0时代是一个群雄并起,逐鹿网络的时代,虽然各个网站采用的手段和方法不同,但第一代互联网有诸多共同的特征,表现在技术创新主导模式.基于点击流量的盈利 ...

  9. networkComms 通信框架之 消息处理器

    经常做Tcp通信的朋友知道,客户端发送数据到服务器 或者 服务器发送消息到客户端,接收端都要有相对应的处理器来对消息进行处理. 这里有两个概念 需要进行区别 消息类型 实际的数据类型  这里指的是未被 ...

  10. 点读系列《流畅的python》

    第1章 python数据模型 python的写法是由背后的魔法方法实现的,比如obj[key],解释器实际调用的是obj.__getitem__(key) 作者把魔法方法叫做双下方法,因为有两个下划线 ...