Lvalue&是什么? rvalue(旧的c.l.c.帖子遍布地图)? [英] What exactly is lvalue & rvalue (old c.l.c. posts are all over the map)?

查看:77
本文介绍了Lvalue&是什么? rvalue(旧的c.l.c.帖子遍布地图)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这里有没有人对

术语左值的含义有深刻的理解。和rvalue因为它涉及C,对象和不同的

上下文?如果是这样的话请分享。


我一直在阅读关于这个主题的几个老帖子/帖子,他们

永远不会以结论结束(人们保持彼此纠正并且

不同意。


我对它的看法是左值。是一个表达式,它指的是一个

对象(可以在其中包含(a)值),以及rvalue对象。是一个

表达式,只有一个值(短暂的价值,因为Chris Torek将会b / b
声明)并且与对象无关。


就其用途而言,左值是指左值。这是指类型为T的对象,

可以在某个地方使用rvalue。具有类型T的那个可以是,但不是

反之亦然。因此,如果一个人使用一个左值引用一个int变量在
中需要一个int值的上下文,那么只需将该值放在

中,该对象就会被转移到该上下文中。


这是一个公平的描述吗?

Hi,

Does anyone here have a strong understanding for the meanings of the
terms "lvalue" and "rvalue" as it pertains to C, objects, and different
contexts? If so please share.

I''ve been reading several old posts/threads on the subject, and they
never end with a conclusion (people keep correcting each other and
disagreeing).

My take on it is that an "lvalue" is an expression that refers to an
object (which can have (a) value(s) within it), and "rvalue" is an
expression that only has a value (ephemeral value as Chris Torek would
claim) and no association with an object.

As far as their use, an "lvalue" that refers to an object of type T,
can be used anwhere an "rvalue" that that has a type T can be, but not
vice versa. So if one uses an lvalue that refers to an int variable in
an context that requires an int value, then simply the value sitting in
the object is dumped into that context.

Is this a fair description?

推荐答案

Romeo Colacitti写道:
Romeo Colacitti wrote:


这里有没有人对
术语左值的含义有深刻的理解。和rvalue因为它涉及C,对象和
不同的上下文?如果是这样的话请分享。

我一直在阅读关于这个主题的几个老帖子/帖子,而且他们永远不会得出结论(人们不断纠正彼此和
不同意。

我对它的看法是左值。是一个表达式,它指的是一个
对象(可以在其中包含(a)值),以及rvalue。是一个
表达式,只有一个值(短暂值,如Chris Torek
指出)>并且与对象没有关联。
就它们的使用而言,左值是一个左值。这是指类型为T的对象,
可以在rvalue的地方使用。具有类型T的那个可以是,但是
反之亦然。因此,如果在需要int值的上下文中使用引用int变量
的左值,则只需将对象中的
值转储到该上下文中。
这是一个公平的描述吗?
Hi,

Does anyone here have a strong understanding for the meanings of the
terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share.

I''ve been reading several old posts/threads on the subject, and they
never end with a conclusion (people keep correcting each other and
disagreeing).

My take on it is that an "lvalue" is an expression that refers to an
object (which can have (a) value(s) within it), and "rvalue" is an
expression that only has a value (ephemeral value as Chris Torek points out) >and no association with an object.
As far as their use, an "lvalue" that refers to an object of type T,
can be used anwhere an "rvalue" that that has a type T can be, but not vice versa. So if one uses an lvalue that refers to an int variable in an context that requires an int value, then simply the value sitting in the object is dumped into that context.

Is this a fair description?




两者都是左值和(r)价值 [目前的标准更愿意忽略

''r''并坚持''l''的意思''定位'''是表达式。


有些表达式是左值,有些则是右值。 是是我是/ b $ b意思是,评估结果是什么。 "表达"不必是一个完整的

表达式,但也指子表达式(即使是变量名称的
令牌序列)。


在不需要对象的上下文中使用时,每个左值都将转换为

中表示的对应(r)值

( value上下文),除了引用和数组对象的左值

类型(它被转换为(r)值等于
$ b $的地址b数组的第一个元素和指向T的类型指针。


当在一般对象上下文中使用左值时,那么左值

将被直接采取行动(不会转换为右值)。

例子是&和sizeof。


还有另一种特殊类型的对象上下文。这不需要

只是一个左值,而是一个MODIFIABLE左值。这些特殊物品

contexts包含涉及++, - 和左手的表达式

两个=和op =的边。因此,只有可修改的左值可以在这里使用,并且它们包括所有非值的左值:数组名称,

与声明为const的对象相关联,或者与对象连接

不完整类型(这些是不可修改的左值)。

所有其他上下文/运算符(除非我错过了一些)需要(r)值

作为他们的表达/操作数。例如,函数

调用中的参数应该是(r)值表达式(但我们也会左右估算
表达式,但它们会自动转换为(r)值

由其关联对象表示。

[另一种说法是,函数调用参数是value

context ]


希望这会有所帮助。



Both "lvalue" and "(r)value" [current standards prefer to leave out the
''r'' and insist that the ''l'' means ''locator''] are expressions.

Some expressions are lvalues, while others are rvalues. By "are" I
mean, "evaluate to results that are." "Expression" need not be a full
expression but refers also to subexpressions too (even down to a
token-sequence for a variable name).

Every lvalue is converted to the corresponding (r)value represented in
it''s object when used in a context that does not need an object
("value" context), EXCEPT for an lvalue referring to and array object
of type T (it is converted to an (r)value equal to the address of the
first element of the array and of type pointer to T).

When an lvalue is used in an "general object context," then the lvalue
is directly acted upon (no conversion to an rvalue takes place).
Examples are & and sizeof.

There is another special type of "object context" that requires not
only an lvalue, but a MODIFIABLE lvalue. These "special objects
contexts" include expressions involved with ++, --, and the left hand
sides of both = and op= . So only lvalues that are modifiable can be
used here, and they include all lvalues that are NOT: array names,
connected with objects declared as const, or connected with objects of
incomplete type (these are nonmodifiable lvalues).
All other contexts/operators (unless I missed some) require (r)values
as their expressions/operands. For example, arguments in function
calls are expected to be (r)value expressions (but we also lvalues
expressions, but they are automatically converted to the (r)values
represented by their associated objects).
[Another way to say this is, the function call arguments is of "value"
context]

Hope this helps.


Romeo Colacitti写道:
Romeo Colacitti wrote:

这里有没有人对
术语左值的含义有深刻的理解。和rvalue因为它涉及C,对象,
和不同的上下文?如果是这样的话请分享。

我一直在阅读关于这个主题的几个老帖子/帖子,而且他们永远不会得出结论(人们不断纠正彼此和
不同意。

我对它的看法是左值。是一个表达式,它指的是一个
对象(可以在其中包含(a)值),以及rvalue。是一个
表达式,只有一个值(Chris Torek会声称的短暂值)并且与对象没有关联。

就他们的使用而言,是一个左值 ;这是指类型为T的对象,
可以在rvalue的地方使用。具有类型T的那个可以是,但不是反之亦然。
因此,如果使用左值引用需要int值的上下文中的int变量,
然后只是坐在对象中的价值被倾倒到那个环境中。

这是一个公平的描述吗?

Hi,

Does anyone here have a strong understanding for the meanings of the
terms "lvalue" and "rvalue" as it pertains to C, objects,
and different contexts? If so please share.

I''ve been reading several old posts/threads on the subject, and they
never end with a conclusion (people keep correcting each other and
disagreeing).

My take on it is that an "lvalue" is an expression that refers to an
object (which can have (a) value(s) within it), and "rvalue" is an
expression that only has a value (ephemeral value as Chris Torek would
claim) and no association with an object.

As far as their use, an "lvalue" that refers to an object of type T,
can be used anwhere an "rvalue" that that has a type T can be, but not
vice versa.
So if one uses an lvalue that refers to an int variable in
an context that requires an int value,
then simply the value sitting in
the object is dumped into that context.

Is this a fair description?




lvalue,rvalue的区别

是可以在编译时确定的。

如果你有

int array [1];

然后

数组[-1]是一个左值的例子,它没有将
引用到一个对象。使用这样的左值将是不确定的行为。


-

pete



The lvalue, rvalue distinction
is something that can be determined at compile time.
If you have
int array[1];
then
array[-1] is an example of an lvalue which doesn''t refer
to an object. The use of such an lvalue would be undefined behavior.

--
pete


In文章< 42 *********** @ mindspring.com>

pete< pf ***** @ mindspring.com>写道:
In article <42***********@mindspring.com>
pete <pf*****@mindspring.com> wrote:
左值,左值区别
是可以在编译时确定的。


好​​吧,在C99,也许吧。 :-) C89定义部分地说,如果有一个类型为T *的指针,那么




T * p;


然后* p是左值,当且仅当p实际指向

对象时。因此,在:


p = malloc(sizeof * p);

* p = some_T_value();


* p如果malloc()成功,则是左值,但如果失败则不是

(返回NULL)。


这当然是荒谬的情况,这就是为什么N869

草案措辞说*在所有情况下* p都是左值 - 即使例如

p == NULL - 但如果p确实效果不明确

没有指向类型为T的有效对象。


不幸的是,C99定义显然也有缺陷

(见过去的讨论在这里和comp.std.c)。


这些条款可以追溯到(至少)Algol,意图很明确

够了:左值出现在赋值运算符的左侧,

和rvalues出现在右侧 - 因此名称左值和

正确的价值。在缺乏C'丰富的运算符的语言中,

这样的简单定义就足够了;我们写道:


a:= b;


并且没有像b ++这样的东西。弄乱这个问题。 C混合

一切都变成了一个奇妙的,令人困惑的混乱,甚至编译器编写者有时会弄错。 :-)

如果你有
int array [1];
那么
array [-1]是一个没有引用的左值的例子
一个对象。使用这样的左值将是未定义的行为。
The lvalue, rvalue distinction
is something that can be determined at compile time.
Well, in C99, maybe. :-) The C89 definition says, in part, that
if one has a pointer of type "T *":

T *p;

then *p is an lvalue if and only if p actually points to an
object. Thus, in:

p = malloc(sizeof *p);
*p = some_T_value();

"*p" is an lvalue if malloc() succeeded, but not if it failed
(returned NULL).

This is of course a ridiculous situation, which is why the N869
draft wording says that *p is an lvalue in all cases -- even if
p==NULL for instance -- but that the effect is undefined if p does
not point to a valid object of type T.

Unfortunately, the C99 definition is apparently defective as well
(see past discussion here and in comp.std.c).

The terms date back to (at least) Algol, and the intent is clear
enough: lvalues occur on the left side of assignment operators,
and rvalues occur on the right -- hence the names "left value" and
"right value". In languages that lack C''s profusion of operators,
a simple definition like this suffices; we write:

a := b;

and there is nothing like "b++" to clutter up the issue. C mixes
everything up into a wonderful, confusing jumble, and even
compiler-writers sometimes get it wrong. :-)
If you have
int array[1];
then
array[-1] is an example of an lvalue which doesn''t refer
to an object. The use of such an lvalue would be undefined behavior.




再次,在C99中显然是正确的,但在C89中没有(技术上)。但

这只是意味着C89标准有缺陷。

-

现实生活中:克里斯托雷克,风河系统

美国犹他州盐湖城(40°39.22''N,111°50.29''W)+1 801 277 2603

电子邮件:忘了它 http://web.torek.net/torek/index.html

由于垃圾邮件发送者,阅读电子邮件就像在垃圾中搜索食物一样。



Again, apparently true in C99, but not (technically) in C89. But
this just means the C89 standard has a defect.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22''N, 111°50.29''W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.


这篇关于Lvalue&amp;是什么? rvalue(旧的c.l.c.帖子遍布地图)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆