青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 10  文章 - 0  trackbacks - 0
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

靜心學習,好好珍惜身邊的人。

常用鏈接

留言簿(1)

隨筆分類

隨筆檔案

搜索

  •  

積分與排名

  • 積分 - 3829
  • 排名 - 1720

最新評論

閱讀排行榜

評論排行榜

If you've been programming in either C or C++ for a while, it's likely that you've heard the terms lvalue (pronounced "ELL-value") and rvalue (pronounced "AR-value"), if only because they occasionally appear in compiler error messages. There's also a good chance that you have only a vague understanding of what they are. If so, it's not your fault.

Most books on C or C++ do not explain lvalues and rvalues very well. (I looked in a dozen books and couldn't find one explanation I liked.) This may be due to of the lack of a consistent definition even among the language standards. The 1999 C Standard defines lvalue differently from the 1989 C Standard, and each of those definitions is different from the one in the C++ Standard. And none of the standards is clear.

Given the disparity in the definitions for lvalue and rvalue among the language standards, I'm not prepared to offer precise definitions. However, I can explain the underlying concepts common to the standards.

As is often the case with discussions of esoteric language concepts, it's reasonable for you to ask why you should care. Admittedly, if you program only in C, you can get by without understanding what lvalues and rvalues really are. Many programmers do. But understanding lvalues and rvalues provides valuable insights into the behavior of built-in operators and the code compilers generate to execute those operators. If you program in C++, understanding the built-in operators is essential background for writing well-behaved overloaded operators.

Basic concepts
Kernighan and Ritchie coined the term lvalue to distinguish certain expressions from others. In The C Programming Language (Prentice-Hall, 1988), they wrote "An object is a manipulatable region of storage; an lvalue is an expression referring to an object....The name 'lvalue' comes from the assignment expression E1 = E2 in which the left operand E1 must be an lvalue expression."

In other words, the left and right operands of an assignment expression are themselves expressions. For the assignment to be valid, the left operand must refer to an object-it must be an lvalue. The right operand can be any expression. It need not be an lvalue. For example:

int n;

declares n as an object of type int. When you use n in an assignment expression such as:

n = 3;

n is an expression (a subexpression of the assignment expression) referring to an int object. The expression n is an lvalue.

Suppose you switch the left and right operands around:

3 = n;

Unless you're a former Fortran programmer, this is obviously a silly thing to do. The assignment is trying to change the value of an integer constant. Fortunately, C and C++ compilers reject it as an error. The basis for the rejection is that, although the assignment's left operand 3 is an expression, it's not an lvalue. It's an rvalue. It doesn't refer to an object; it just represents a value.

I don't know where the term rvalue comes from. Neither edition of the C Standard uses it, other than in a footnote stating "What is sometimes called 'rvalue' is in this standard described as the 'value of an expression.'"

The C++ Standard does use the term rvalue, defining it indirectly with this sentence: "Every expression is either an lvalue or an rvalue." So an rvalue is any expression that is not an lvalue.

Numeric literals, such as 3 and 3.14159, are rvalues. So are character literals, such as 'a'. An identifier that refers to an object is an lvalue, but an identifier that names an enumeration constant is an rvalue. For example:

enum color { red, green, blue };
color c;
...
c = green;    // ok
blue = green;    // error

The second assignment is an error because blue is an rvalue.

Although you can't use an rvalue as an lvalue, you can use an lvalue as an rvalue. For example, given:

int m, n;

you can assign the value in n to the object designated by m using:

m = n;

This assignment uses the lvalue expression n as an rvalue. Strictly speaking, a compiler performs what the C++ Standard calls an lvalue-to-rvalue conversion to obtain the value stored in the object to which n refers.

Lvalues in other expressions
Although lvalues and rvalues got their names from their roles in assignment expressions, the concepts apply in all expressions, even those involving other built-in operators.

For example, both operands of the built-in binary operator + must be expressions. Obviously, those expressions must have suitable types. After conversions, both expressions must have the same arithmetic type, or one expression must have a pointer type and the other must have an integer type. But either operand can be either an lvalue or an rvalue. Thus, both x + 2 and 2 + x are valid expressions.

Although the operands of a binary + operator may be lvalues, the result is always an rvalue. For example, given integer objects m and n:

m + 1 = n;

is an error. The + operator has higher precedence than the = operator. Thus, the assignment expression is equivalent to:

(m + 1) = n;    // error

which is an error because m + 1 is an rvalue.

As another example, the unary & (address-of) operator requires an lvalue as its operand. That is, &n is a valid expression only if n is an lvalue. Thus, an expression such as &3 is an error. Again, 3 does not refer to an object, so it's not addressable.

Although the unary & requires an lvalue as its operand, it's result is an rvalue. For example:

int n, *p;
...
p = &n;    // ok
&n = p;    // error: &n is an rvalue

In contrast to unary &, unary * produces an lvalue as its result. A non-null pointer p always points to an object, so *p is an lvalue. For example:

int a[N];
int *p = a;
...
*p = 3;     // ok

Although the result is an lvalue, the operand can be an rvalue, as in:

*(p + 1) = 4;    // ok

Data storage for rvalues
Conceptually, an rvalue is just a value; it doesn't refer to an object. In practice, it's not that an rvalue can't refer to an object. It's just that an rvalue doesn't necessarily refer to an object. Therefore, both C and C++ insist that you program as if rvalues don't refer to objects.

The assumption that rvalues do not refer to objects gives C and C++ compilers considerable freedom in generating code for rvalue expressions. Consider an assignment such as:

n = 1;

where n is an int. A compiler might generate named data storage initialized with the value 1, as if 1 were an lvalue. It would then generate code to copy from that initialized storage to the storage allocated for n. In assembly language, this might look like:

one: .word 1
...
mov (one), n

Many machines provide instructions with immediate operand addressing, in which the source operand can be part of the instruction rather than separate data. In assembly, this might look like:

mov #1, n

In this case, the rvalue 1 never appears as an object in the data space. Rather, it appears as part of an instruction in the code space.

On some machines, the fastest way to put the value 1 into an object is to clear it and then increment it, as in:

clr n
inc n

Clearing the object sets it to zero. Incrementing adds one. Yet data representing the values 0 and 1 appear nowhere in the object code.

posted on 2008-12-15 10:43 GLORY 閱讀(539) 評論(0)  編輯 收藏 引用 所屬分類: C/C++ Specification
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美高清视频| 欧美搞黄网站| 国产一区二区0| 欧美在线一级va免费观看| 亚洲欧美日本日韩| 国内揄拍国内精品久久| 男女激情久久| 欧美激情va永久在线播放| aa级大片欧美三级| 亚洲无吗在线| 国产综合视频| 最新国产成人av网站网址麻豆| 免费观看亚洲视频大全| 99国产精品一区| 亚洲综合色激情五月| 韩日在线一区| 亚洲美女尤物影院| 国产丝袜一区二区| 亚洲国产mv| 国产精品一区二区三区观看| 欧美在线高清| 欧美成人乱码一区二区三区| 亚洲综合电影| 久热这里只精品99re8久| 99在线热播精品免费| 午夜精品久久久久久久白皮肤 | 在线一区二区日韩| 精品88久久久久88久久久| 亚洲黄色av| 狠狠色丁香久久综合频道| 亚洲欧洲在线一区| 国内成人精品视频| 亚洲先锋成人| 亚洲精品日韩激情在线电影| 亚洲午夜电影在线观看| 亚洲国产精品久久精品怡红院| 99热在这里有精品免费| 国内精品久久久久伊人av| av成人免费在线| 在线观看不卡| 夜夜嗨av一区二区三区中文字幕| 伊人久久大香线| 亚洲丝袜av一区| 亚洲精品九九| 香蕉成人久久| 99精品国产一区二区青青牛奶 | 欧美www在线| 国产日韩精品在线观看| 99国内精品久久| 亚洲精品九九| 亚洲欧美日韩第一区| 一本一本久久a久久精品综合麻豆| 欧美一级一区| 亚洲欧美精品在线| 欧美日韩一区二区三区四区五区| 嫩草影视亚洲| 国产日韩欧美综合| 亚洲一区二区免费在线| 一本色道久久综合亚洲精品按摩| 久久久久久穴| 玖玖精品视频| 国产一区二区三区在线免费观看| 亚洲深夜激情| 午夜精品在线视频| 国产精品青草久久| 一区二区三区回区在观看免费视频| 亚洲国产一成人久久精品| 久久色在线播放| 美女脱光内衣内裤视频久久影院 | 国产精品视频久久一区| 亚洲三级免费观看| 在线亚洲高清视频| 欧美日韩综合视频网址| 在线性视频日韩欧美| 亚洲欧美三级在线| 国产欧美一区二区精品性色| 亚洲欧美日本精品| 久久9热精品视频| 国内外成人在线| 麻豆精品精华液| 91久久国产综合久久蜜月精品| 夜夜爽www精品| 欧美日韩大片| 亚洲欧美日韩国产一区二区三区| 欧美在线视频全部完| 国产一级揄自揄精品视频| 久久精品二区| 母乳一区在线观看| 中国成人在线视频| 国产日韩亚洲欧美精品| 久久久五月婷婷| 亚洲毛片在线免费观看| 欧美一区二区三区视频在线 | 欧美啪啪一区| 亚洲欧美在线看| 欧美激情在线狂野欧美精品| 夜夜嗨一区二区三区| 国产手机视频一区二区| 欧美xx69| 亚洲欧美综合v| 欧美激情视频一区二区三区在线播放 | 欧美不卡激情三级在线观看| 99精品热视频只有精品10| 久久―日本道色综合久久| 亚洲精品视频啊美女在线直播| 国产精品视频福利| 欧美电影免费网站| 亚洲欧美综合国产精品一区| 亚洲国产小视频在线观看| 久久aⅴ乱码一区二区三区| 亚洲美女视频在线免费观看| 国产综合久久久久影院| 欧美特黄一区| 欧美99在线视频观看| 欧美亚洲一区在线| 99在线视频精品| 亚洲国产经典视频| 美脚丝袜一区二区三区在线观看 | 蜜桃av一区二区三区| 亚洲一区二区三区欧美| 亚洲日韩欧美视频一区| 国产一区二区三区高清| 国产精品白丝av嫩草影院| 另类成人小视频在线| 欧美亚洲一级| 亚洲网在线观看| 一区二区精品在线| 亚洲人久久久| 91久久久亚洲精品| 欧美1区2区3区| 久久午夜电影网| 久久精品天堂| 欧美一区二区私人影院日本 | 在线免费观看成人网| 国产欧美va欧美不卡在线| 国产精品久久久久高潮| 欧美日韩精品免费看| 欧美啪啪成人vr| 欧美日韩午夜在线视频| 欧美精品午夜视频| 欧美乱妇高清无乱码| 欧美极品在线播放| 欧美精品一区二区三区一线天视频 | 久久99在线观看| 欧美在线视频播放| 久久成人这里只有精品| 欧美在线1区| 久久国产主播精品| 久久久国产成人精品| 久久精品综合一区| 久久―日本道色综合久久| 美女999久久久精品视频| 免费看成人av| 亚洲第一精品在线| 日韩视频免费看| 亚洲一区二区三区在线视频| 亚洲一区二区三区在线播放| 性做久久久久久久久| 久久久成人精品| 欧美高清视频| 国产精品成人一区二区网站软件 | 欧美韩日一区二区三区| 91久久国产综合久久| 在线亚洲美日韩| 欧美一级黄色录像| 久久综合九色九九| 欧美日韩视频专区在线播放 | 久久精品麻豆| 欧美大片免费久久精品三p| 亚洲高清影视| 亚洲特级毛片| 久久久久欧美精品| 欧美日本二区| 国产精品久久一区二区三区| 国产在线不卡| 一区二区三区精品视频在线观看| 午夜精品99久久免费| 嫩草伊人久久精品少妇av杨幂| 亚洲精品一区在线观看香蕉| 亚洲欧美日韩国产另类专区| 免费在线观看日韩欧美| 国产精品久久久对白| 影音先锋亚洲精品| 亚洲一级高清| 亚洲福利视频免费观看| 亚洲综合首页| 欧美精品日本| 曰韩精品一区二区| 亚洲欧美日韩国产综合在线| 欧美岛国激情| 午夜欧美精品| 欧美精品一区二| 激情成人亚洲| 亚洲欧美色婷婷| 亚洲另类自拍| 欧美3dxxxxhd| 18成人免费观看视频| 欧美一区二区在线视频| 亚洲乱码国产乱码精品精天堂| 久久久久久穴|