Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue (http://www.velocityreviews.com/forums/t444897-operators-requiring-lvalue-rvalue-operands-and-resulting-in-rvalue-lvalue.html)

Kavya 10-27-2006 11:51 AM

operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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?


Bart 10-27-2006 12:08 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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.


Richard Tobin 10-27-2006 12:25 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
In article <1161949909.307015.215980@f16g2000cwb.googlegroups .com>,
Kavya <Lerner84@gmail.com> 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

Ahmed Kalembo 10-27-2006 01:05 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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

Keith Thompson 10-27-2006 07:22 PM

Re: operators requiring lvalue/rvalue operands and resulting inrvalue/lvalue
 
Ahmed Kalembo <null@null.null> 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) kst-u@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.

Ahmed Kalembo 10-27-2006 09:15 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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

Frederick Gotham 10-27-2006 09:17 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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

Frederick Gotham 10-27-2006 09:19 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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

Andrey Tarasevich 10-27-2006 11:51 PM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
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

Dik T. Winter 10-28-2006 01:45 AM

Re: operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue
 
In article <Xns9869E26AFAFBAahmedkalembo@194.125.133.14> Ahmed Kalembo <null@null.null> 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/


All times are GMT. The time now is 03:30 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.