An lvalue is anything that can *legally* appear on the left hand side of an
assignment. What this means is that the value corresponds to a variable
with real memory set aside for storing it. The alter-ego of the lvalue is
the rvalue. An rvalue is an legal value for the right side of an
assignment. In general, any expression that may be used as an lvalue may be
used as an rvalue, but not vice-versa.
Some examples:
int i, j, k;
int *ip, *jp;
i = j; // i is lvalue, j is rvalue
j = 2; // j is lvalue, 2 is rvalue
// note that j is used both as lvalue and rvalue.
2 = i; // ILLEGAL: 2 has no memory associated with it, and cannot
// be assigned to.
i = j + k; // i is lvalue, j + k is rvalue
ip = &i; // ip is lvalue, &i is rvalue
jp = ip; // jp is lvalue, jp is rvalue
&i = j; // ILLEGAL: &i is not an lvalue
*ip = 2; // *ip is a legal lvalue
*ip = *jp; // legal
If you understand the last three, then you probably have a good handle on
this topic. &i is not a real variable. You cannot set the address of a
variable. &j causes the compiler to generate certain constants (probably an
offset into the stack) and constants cannot be changed.
On the other hand, *ip is an lvalue and can be assigned. This is almost by
definition. Since ip is a ptr to memory, then you can change the contents
of that memory. You do that by assigning to *ip.
If you have casts on the left side of the assignment, that could mess you
up, too. Until you really understand what's going on, I recommend that you
avoid casts on the left side.
I suggest that you pick up a *good* book on C or C++. The authors will be
much more lucid and have many more examples than I have been able to here.
Good luck,
George
> From: "Joe Wronski" <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> Date: Wed, 17 Nov 1999 06:16:25 -0500
> To: <[EMAIL PROTECTED]>
> Subject: RE: simple programming question
>
> An lvalue is just what it says it is. The left side of an assignment
> statement. Sometimes it happens when the variable has the same name as a
> defined macro. This happens quite a bit with simple, case-insensitive
> compilers, or when you have long variable names that are internally
> truncated making it non-ambiguous.
>
> Joe W.
>
>> -----Original Message-----
>> From: Palm Dev Forum [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, November 16, 1999 6:08 PM
>> To: [EMAIL PROTECTED]
>> Subject: simple programming question
>>
>>
>> Sometimes I try to compile and get an error where the compiler
>> tells me that
>> my variable is not a "lvalue". Most of the time I just mess
>> around with it
>> until it goes away but I think I would be better off if I fully understood
>> what was going on. Could someone please help me out?
>>
>> Thanks.
>>
>>
>>
>