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

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. tensorflow报错

    libcublas.so.9.0: cannot open shared object file: No such file or directory 输入命令: sudo ldconfig/usr/ ...

  2. python3 实现简单ftp服务功能(服务端 For Linux)

    转载请注明出处! 功能介绍: 可执行的命令: lspwdcd put rm get mkdir 1.用户加密认证 2.允许多用户同时登陆 3.每个用户有自己的家目录,且只可以访问自己的家目录 4.运行 ...

  3. The First Scrum Meeting!

    第六周会议 情况简述 会议概要:明确需求,确定目标 参与人员:詹晓宇  谢赛金  熊紫仁  徐翠萍  周娟  孙尚煜 讨论时间:2019-10-24 会议地点:六区研讨性教室 具体内容 根据之前做的P ...

  4. thinkphp生成二维码

    /** * 生成二维码 * @param string $url url连接 * @param integer $size 尺寸 纯数字 */ function qrcode($url,$size=4 ...

  5. 外部表及oracle数据库内存

    create table alert1 (log varchar2(1000))2 organization external3 (type oracle_loader4 default direct ...

  6. 【Tomcat】1.Tomcat在Windows系统的安装和使用

    1.下载与安装 安装Tomcat的[前提条件]是安装好JDK或者JRE(本文略过)Tomcat在Windows系统中可以通过[压缩包]或[安装包]来安装建议使用[安装包]来简化安装步骤登录官网http ...

  7. windows2003 disk mirror failed redundency

    操作前請確認 mirror 磁盤已備份 windows2003 disk mirror failed redundency時,offline + online並不可以自動修復. 需要offline f ...

  8. 埋在MySQL数据库应用中的17个关键问题

    出处:https://blog.csdn.net/weixin_42882439 MySQL的使用非常普遍,跟MySQL有关的话题也非常多,如性能优化.高可用性.强一致性.安全.备份.集群.横向扩展. ...

  9. spring相关注解

    spring相关注解: 使用之前需要<context:annotation-config/>在配置文件中启用 @Required 应用于类属性的set方法,并且要求该属性必须在xml容器里 ...

  10. numpy 中文手册

    https://yiyibooks.cn/xx/NumPy_v111/user/index.html