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

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. security 页面测试

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  2. mysql 获取任意一个月的所有天数。

    SELECT ADDDATE(y.first, x.d - 1) as dFROM(SELECT 1 AS d UNION ALLSELECT 2 UNION ALLSELECT 3 UNION AL ...

  3. HTTP 错误 500.21 - Internal Server Error处理程序“NickLeeCallbackHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    HTTP 错误 500.21 - Internal Server Error处理程序“NickLeeCallbackHandler”在其模块列表中有一个错误模块“ManagedPipelineHand ...

  4. FZU 2150 Fire Game (高姿势bfs--两个起点)

    Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...

  5. mysql学习-join的使用

    sql的执行顺序是从from 开始 join图

  6. 学习java web中的listener

    web.xml里的顺序为:context-param->listener->filter->servlet 监听器是需要新建一个类,然后按监听的对象继承:ServletContext ...

  7. 后端优化(2)—— BA与图优化

  8. css 导航菜单+下拉菜单

    一.导航菜单 1.横向导航 代码如下: <!doctype html> <html> <head> <meta charset="utf-8&quo ...

  9. hdu6578 2019湖南省赛D题Modulo Nine 经典dp

    目录 题目 解析 AC_Code @ 题目 第一题题意是一共有{0,1,2,3}四种数字供选择,问有多少个长度为n的序列满足所有m个条件,每个条件是说区间[L,R]内必须有恰好x个不同的数字. 第二题 ...

  10. js中文首字母数组排序

    js中文首字母数组排序 数组的排序js算法: var Pinyin = (function() { var Pinyin = function(ops) { this.initialize(ops); ...