From: Hendrik Schober on
Hi,

as a second job I am teaching C++. I have only 3-4 months to
teach it to students who had two semesters of exposure to
Java.
What I have learned doing this is that I need to find concise
definitions for everything I want them to remember. Sometimes
such definitions are surprisingly hard to find.
One of the problems I keep running into is finding a good
answer to the question "What's an lvalue/rvalue?" I have asked
for a concise definition for this in newsgroups several times
and searched the archives for other discussions of the topic,
so I know impossible to come up with an easy definition. Yet I
really do need to come up with a definition myself that needs
to be simple enough to be remembered by my students while still
being correct. (This will become even more urgent once rvalue
references will become available.)
So is there any short enough description this groupd can come
up with?

TIA,

Schobi

--
SpamTrap(a)gmx.de is never read
I'm HSchober at gmx dot de
"The trouble with being a god is that you've got
no one to pray to." Terry Pratchett



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Martin York on
On Mar 31, 2:31 am, "Hendrik Schober" <SpamT...(a)gmx.de> wrote:
> Hi,
>
> as a second job I am teaching C++. I have only 3-4 months to
> teach it to students who had two semesters of exposure to
> Java.
>
> One of the problems I keep running into is finding a good
> answer to the question "What's an lvalue/rvalue?"

Simple (but not too simplistic) and easy to remember
=====================================================
lvalue: an expression that can be placed on the left hand side of an
assignment.
rvalue: an expression that can be placed on the right hand side of an
assignment.

Note: rvalue can NOT go on the left because they are basically read
only.
Note: lvalue CAN go on both sides (if you can write to it you can read
it).

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: restor on
I asked that question once in comp.std.c++. Here is the link:
http://groups.google.co.uk/group/comp.std.c++/browse_thread/thread/ec79707a128de78d/5cffdaed89370523?hl=en&lnk=st&q=#5cffdaed89370523
The view emerging from the discussion was that the description of
lvalue/rvalue can be either precise or short, but not both. I
understand that rvalue used to represent a value of something and
lvalue used to represent a piece of storage where the value could be
stored. But this no longer holds and you could find many
counterexamples to this description. Better description of rvalue
would be that it is either a temporary or a literal. One of the aims
of rvalue references is to filter temporaries from non-temporaries.

Regards,
&rzej

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Greg Herlihy on
On Mar 31, 2:31 am, "Hendrik Schober" <SpamT...(a)gmx.de> wrote:
> One of the problems I keep running into is finding a good
> answer to the question "What's an lvalue/rvalue?"
> ...
> So is there any short enough description this groupd can come
> up with?

An "lvalue" is a value that resides in program memory (so an lvalue is
an "addressable" value). The value of an "rvalue" is one that -
conceptually at least - does not require storage in program memory.
(So, unlike the value of an lvalue, the value of an rvalue is usually
not accessible indirectly, say, via a pointer or a reference).

In practical terms, an rvalue often represents a value that is loaded
directly into a machine register or a value that is incorporated into
a particular machine instruction (such as an "immediate" value in an
"add immediate" assembly language instruction).

Greg



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Alberto Ganesh Barbati on
Hendrik Schober ha scritto:
> Hi,
>
> as a second job I am teaching C++. I have only 3-4 months to
> teach it to students who had two semesters of exposure to
> Java.
> What I have learned doing this is that I need to find concise
> definitions for everything I want them to remember. Sometimes
> such definitions are surprisingly hard to find.
> One of the problems I keep running into is finding a good
> answer to the question "What's an lvalue/rvalue?" I have asked
> for a concise definition for this in newsgroups several times
> and searched the archives for other discussions of the topic,
> so I know impossible to come up with an easy definition. Yet I
> really do need to come up with a definition myself that needs
> to be simple enough to be remembered by my students while still
> being correct. (This will become even more urgent once rvalue
> references will become available.)
> So is there any short enough description this groupd can come
> up with?

You couldn't find a concise definition, because lvalues and rvalues are
not defined abstractly in terms of one or more properties they may
possess, but they are defined constructively in terms of how you can
obtain them.

An rvalue is:

- the value yielded by certain built-in operators (for example +, -, /,
etc.), or

- the result of calling a function that does not return a reference, or

- an expression which holds a temporary object resulting from a cast to
a nonreference type.

Every expression which is not an rvalue is an lvalue.

You may find this "definitions" unsatisfactory, however they are, to my
knowledge, the most accurate.

There was a legacy definition of lvalue which come from the C language
that says "an lvalue is an expression that you could put on the left
side of an assigment". The "l" in lvalue in fact stands for "left". For
contrast, when the concept of non-lvalue was subsequently introduced, it
was natural to use the term rvalue with the "r" standing for "right".
However, this definition is no longer acceptable in C++ (nor in C)
because of the introduction of the const qualifier: you can have const
lvalues which are lvalues but can't be used as assignment targets.

HTH,

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]