By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Oct 27 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Kavya wrote:
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.

Oct 27 '06 #2

P: n/a
In article <11**********************@f16g2000cwb.googlegroups .com>,
Kavya <Le******@gmail.comwrote:
>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
Oct 27 '06 #3

P: n/a
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

--
Ahmed Kalembo
Oct 27 '06 #4

P: n/a
Ahmed Kalembo <nu**@null.nullwrites:
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.
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Oct 27 '06 #5

P: n/a
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."

--
Ahmed Kalembo
Oct 27 '06 #6

P: n/a
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.

--

Frederick Gotham
Oct 27 '06 #7

P: n/a
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.

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

--

Frederick Gotham
Oct 27 '06 #8

P: n/a
Kavya wrote:
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?

--
Best regards,
Andrey Tarasevich
Oct 27 '06 #9

P: n/a
In article <Xn**************************@194.125.133.14Ahme d Kalembo <nu**@null.nullwrites:
....
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.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Oct 28 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.