It seems to me that lvalue stands for "legal value", just a valid
expression in that context.

LS> A.Kazantsev wrote:
>> Agree. And what does the {lval} in the error message exactly mean?

LS> It probably means that the expression whose type was shown was
LS> an lvalue.

LS> An lvalue is something that can be assigned to, i.e. a writeable value.
LS> It's a weird name, but I think it's called that because it's something
LS> that can appear on the lefthand side of an assignment operator.

LS> In C/C++, not only can variables be lvalues (as in "a = 1"), but
LS> more complex expressions can be lvalues too.  For example, this
LS> code will print "a is 1":

LS>     int a, b;

LS>     b = 5;
LS>     (a = b) = 1;

LS>     std::cout << "a is " << a << std::endl;

LS> What's going on is that "(a = b)" forms an expression that can
LS> be assigned to (an lvalue), and when you assign to that expression,
LS> you change the value of the variable a.

LS> As for why the compiler prints the "{lval}" in the error message
LS> for passing arguments to a function, I can't say for sure.  At
LS> first, it seems a little odd because function arguments in C are
LS> by value only, so it wouldn't matter if it's an lvalue.  But in
LS> C++, you can call by reference, so maybe it could matter.

LS> For instance:

LS>     void increment (int& n)
LS>     {
LS>         n++;
LS>     }

LS>     int myfunction ()
LS>     {
LS>         int a;

LS>         increment (a = 1);

LS>         std::cout << "a is " << a << std::endl;
LS>     }

LS> I might be wrong (I don't know the C++ specification by heart), but
LS> I believe this is valid C++ code and it prints "a is 2".

LS> What's going on is this:

LS> (1)  increment() needs to be called, so...
LS> (2)  "a = 1" is evaluated, causing the side-effect of modifying "a"
LS>       to be 1.  the value of the "a = 1" expression is the value of
LS>       "a", which is numerically 1 and also an lvalue.
LS> (3)  The lvalue is passed by reference to increment(), which
LS>       then uses it to modify "a".

LS> Of course, this is very very bad style and highly confusing code,
LS> but the point is that if it's legal like I think it is, then the
LS> compiler might be putting "{lval}" in the error message on purpose,
LS> because it might actually mean something in some cases.  Hmm,
LS> in particular it might be helpful if you try to pass a value
LS> which isn't an lvalue to a function that (because of a reference
LS> type on its argument) requires one.

LS>    - Logan




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to