Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue

Reply
Thread Tools

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

 
 
Kavya
Guest
Posts: n/a
 
      10-27-2006
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?

 
Reply With Quote
 
 
 
 
Bart
Guest
Posts: n/a
 
      10-27-2006
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.

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      10-27-2006
In article <(E-Mail Removed) .com>,
Kavya <(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
Ahmed Kalembo
Guest
Posts: n/a
 
      10-27-2006
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
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-27-2006
Ahmed Kalembo <(E-Mail Removed)> writes:
> 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Ahmed Kalembo
Guest
Posts: n/a
 
      10-27-2006
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
 
Reply With Quote
 
Frederick Gotham
Guest
Posts: n/a
 
      10-27-2006
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
 
Reply With Quote
 
Frederick Gotham
Guest
Posts: n/a
 
      10-27-2006
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
 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      10-27-2006
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
 
Reply With Quote
 
Dik T. Winter
Guest
Posts: n/a
 
      10-28-2006
In article <Xns9869E26AFAFBAahmedkalembo@194.125.133.14> Ahmed Kalembo <(E-Mail Removed)> writes:
....
> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
more on operands' binding and evaluation order Ersek, Laszlo C Programming 11 06-23-2010 09:34 AM
Conversion rules between unsigned operands and signed operand somenath C Programming 11 07-30-2007 10:37 AM
Problem with SLL: "sll can not have such operands in this context" and bit-testing Frank Buss VHDL 5 07-01-2006 04:26 PM
Modulus and negative operands August Karlstrom C Programming 4 01-12-2006 07:56 PM
operands for relational operators <, >, >= etc Greenhorn C Programming 8 03-06-2005 07:14 PM



Advertisments