zoukankan      html  css  js  c++  java
  • C中的lvalue和rvalue

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

    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这两个命令。

  • 相关阅读:
    TensorFlow神经网络集成方案
    过滤节点
    获取子节点
    获取兄弟节点
    获取父节点
    遍历DOM树
    获取修改CSS
    获取修改元素属性
    获取修改value
    获取更新元素文本html()
  • 原文地址:https://www.cnblogs.com/freshair_cnblog/p/11686686.html
Copyright © 2011-2022 走看看