Re: r- r-value vs l-value?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 07 Jun 2006 01:35:29 GMT
"SuperKoko" <tabkannaz@xxxxxxxx> writes:
Chris Smith wrote:Since there is a lot of confusion in that discussion, I'll give rules
Sure. An l-value is an expression that may legally appear on the left-
hand side of the assignment operator, =. An r-value is an expression
that may appear on the right-hand side. The set of r-values is a subset
of the the set of l-values. For example, given:
The following are l-values (and also r-values):
Whereas the following are ONLY r-values:
a + 5
Therefore, the following line of code will fail to compile:
a + 5 = 15;
Hope that helps,
Where are the rules of what may go on each side?
(based on C++).
How are rules based on C++ helpful in comp.lang.c?
First, I'll correct statements of Chris Smith:
a is an lvalue
b is an lvalue
17 is an rvalue
a+5 is an rvalue
b *is an lvalue*
b is the name of an array object. As an expression of array type,
if it's not the operand of a unary "&" or "sizeof" operator, it is
implicitly converted to a pointer. C99 18.104.22.168p3:
Except when it is the operand of the sizeof operator or the unary
& operator, or is a string literal used to initialize an array, an
expression that has type "array of _type_" is converted to an
expression with type "pointer to _type_" that points to the
initial element of the array object and is not an lvalue.
Before this conversion takes place, b is an lvalue; after the
conversion, it isn't. Since there isn't really a "before" and
"after", I suppose you could think of it as a kind of Schroedinger's
lvalues are not rvalues and rvalues are not lvalues... They are totally
The C standard doesn't use the term "rvalue" except in a single
footnote, which says:
What is sometimes called "rvalue" is in this International
Standard described as the "value of an expression".
If an lvalue-expression is found in a context where an rvalue is
expected, an rvalue-to-lvalue conversion occurs (and this conversion is
not conceptual... Physical things occur... And HERE can happen
I think you mean an lvalue-to-rvalue conversion. I suppose this
refers to fetching the value of the designated object.
Comma operator: It doesn't expect any particular type of value (i.e. it[...]
accepts both lvalues and rvalues with different semantics).
In C, AFAIK, the left operand can be either an rvalue or an lvalue and
the value is discarded (as in C++), but the right operand is expected
to be an rvalue, and the expression yields an rvalue.
In C, the operands are expressions. The left operand is evaluated and
its result is discarded. The right operand is then evaluated and its
result becomes the result of the operation. No need to talk about
If you want to know all the C++ rules for conditional expressions, look
And if you want to discuss those rules, I recommend comp.lang.c++.
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
- Re: r- r-value vs l-value?
- From: Old Wolf
- Re: r- r-value vs l-value?
- Prev by Date: Re: Yet another pointer issue!!
- Next by Date: Re: help with a funcition-please
- Previous by thread: Re: r- r-value vs l-value?
- Next by thread: Re: r- r-value vs l-value?