Taras_96
12/9/2008 10:20:00 PM
On Dec 9, 3:56 am, Jack Klein <jackkl...@spamcop.net> wrote:
> On Mon, 8 Dec 2008 15:40:00 -0800 (PST), Taras_96 <taras...@gmail.com>
> wrote in comp.lang.c++:
>
>
> > However, I still don't understand how a string literal can be
> > considered an l-value. The following excerpts hint at an answer:
>
> Do you understand the actual definition of an lvalue? An lvalue
> refers to an object or function. Do you understand the definition of
> an object? An object is a region of storage. So a reference to
> anything that occupies storage is a valid lvalue.
>
Stroustrup states that: "there is a need for a name for "something in
memory." This is the simplest and most fundamental notion of an
object. That is, an /object/ is a contiguous region of storage; an /
lvalue/ is an expression that refers to an object"
But in a sense, the '5' in the expression:
int i = 5;
would be stored somewhere in memory (ultimately, unless it is
optimised out). I suppose that '5' can not be an l-value, because it
isn't an expression that refers to an object (it actually is the
object itself).
Additionally, K&R states that: "An object is a manipulatable region of
storage; an lvalue is an expression referring to an object"
I suppose with that in mind you can't really modify the value of 5, so
with this definition '5' isn't an object.
I'm thinking of an r-value more like a 'concept' rather than a an
object, if that makes any sense. You can not change the 'concept' of
the number 5, 5 will always be 5. This is re-inforced in C++ by only
allowing to take a constant reference to temporaries:
const int & rr = 3;
Otherwise, you could do something like this:
rr = 4;
which would then change 3 to be equal to 4, which doesn't make sense!