operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue

K

Kavya

These were the questions asked to me by my friend

1. Operator which may require an lvalue operand, yet yield an rvalue.
2. Operator which may require an rvalue operand, yet yield an lvalue.

My answer to these questions are & and * respectively.

Is/Are there any other operator(s) satisfying these criteria?
 
B

Bart

Kavya said:
These were the questions asked to me by my friend

1. Operator which may require an lvalue operand, yet yield an rvalue.
2. Operator which may require an rvalue operand, yet yield an lvalue.

My answer to these questions are & and * respectively.

The * operator doesn't require an rvalue.
Is/Are there any other operator(s) satisfying these criteria?

The [] operator.

Regards,
Bart.
 
R

Richard Tobin

Kavya said:
1. Operator which may require an lvalue operand, yet yield an rvalue.

Surely *all* operators yield rvalues? Or do you mean "rvalue which is
not an lvalue"? (The standard does not define "rvalue", but a footnote
says it is the same as the "value of an expression".)

The argument to & may be a function name, which is not an lvalue.

The ++ and -- operators require an lvalue and do not yield one.
2. Operator which may require an rvalue operand, yet yield an lvalue.

Similarly, surely all operators require rvalue operands? Presumably
you mean "rvalue that is not necessarily an lvalue".

The operators [] and -> also produce lvalues from things that are not
necessarily lvalues.

-- Richard
 
A

Ahmed Kalembo

Richard Tobin:
Surely *all* operators yield rvalues?


I believe the general consensus is that an expression is labelled either as
an R-value or an L-value, not that an L-value also qualifies as an R-value.

By this understanding, the following expression works upon an R-value, yet
yields an L-value:

*p
 
K

Keith Thompson

Ahmed Kalembo said:
Richard Tobin:


I believe the general consensus is that an expression is labelled either as
an R-value or an L-value, not that an L-value also qualifies as an R-value.

The term "lvalue" is defined by the standard (though the definition is
very poorly worded); the term "rvalue" is informally defined by the
standard in a footnote. Any "consensus" about what they mean is
irrelevant, at least in this newsgroup.
 
A

Ahmed Kalembo

Keith Thompson:
The term "lvalue" is defined by the standard (though the definition is
very poorly worded); the term "rvalue" is informally defined by the
standard in a footnote. Any "consensus" about what they mean is
irrelevant, at least in this newsgroup.


Consider the two concepts:

(1) declaration
(2) definition

A "declaration" is also a "definition", but not vice-versa. What I was trying
to express is that the L-value and R-value situation is dissimilar to this.
While it is correct to say that a "definition" is also "declaration", I don't
believe that it's right to say that an "L-value" is an "R-value", because I
believe that by calling something an "R-value", you're explicitly saying that
it is _not_ an L-value.

It is true that an L-value can do everything (and more) that an R-value can
do, but I wouldn't go so far as to say that it's OK to call an L-value an R-
value.

In short, if you were to tell me that something is an R-value, I'd interpret
it as:
"This is an R-value, not an L-value."
 
F

Frederick Gotham

Ahmed Kalembo:
A "declaration" is also a "definition", but not vice-versa.


I worded that wrongly; I should have written:

A "definition" is also a "declaration", but not vice-versa.
 
F

Frederick Gotham

Frederick Gotham:
Ahmed Kalembo:



I worded that wrongly; I should have written:

A "definition" is also a "declaration", but not vice-versa.


Sorry about the name mix-up. I'm not socket-puppeting, the computer I'm using
has multiple users at the moment.
 
A

Andrey Tarasevich

Kavya said:
These were the questions asked to me by my friend

1. Operator which may require an lvalue operand, yet yield an rvalue.
2. Operator which may require an rvalue operand, yet yield an lvalue.
...

What exactly is the meaning of "require" in "require an rvalue operand"? Take
the unary '-' for example. It operates on rvalues, but one can always use a
valid lvalue as an operand (which will be implicitly converted to an rvalue).
Does that mean that unary '-' actually _requires_ an rvalue or not?
 
D

Dik T. Winter

> What I was trying
> to express is that the L-value and R-value situation is dissimilar to this.
> While it is correct to say that a "definition" is also "declaration", I
> don't believe that it's right to say that an "L-value" is an "R-value",
> because I believe that by calling something an "R-value", you're
> explicitly saying that it is _not_ an L-value.

That may be your opinion, but that is not necessarily the opinion of
others. There is nothing in the standard (or elsewhere) that would
make something calling an "R-value" that same something not an "L-value".
That is what you get when you are using terms that are undefined. My
reading has always been that an "L-value" (in principle) can be used
at the left side of an assignment and an "R-value" at the right side.
(I ignore the non-midifiable "L-values".)
> It is true that an L-value can do everything (and more) that an R-value can
> do, but I wouldn't go so far as to say that it's OK to call an L-value an R-
> value.

You just use your personal definition of "R-value", apparently.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top