A.Kazantsev wrote:
Agree. And what does the {lval} in the error message exactly mean?
It probably means that the expression whose type was shown was
an lvalue.
An lvalue is something that can be assigned to, i.e. a writeable value.
It's a weird name, but I think it's called that because it's something
that can appear on the lefthand side of an assignment operator.
In C/C++, not only can variables be lvalues (as in "a = 1"), but
more complex expressions can be lvalues too. For example, this
code will print "a is 1":
int a, b;
b = 5;
(a = b) = 1;
std::cout << "a is " << a << std::endl;
What's going on is that "(a = b)" forms an expression that can
be assigned to (an lvalue), and when you assign to that expression,
you change the value of the variable a.
As for why the compiler prints the "{lval}" in the error message
for passing arguments to a function, I can't say for sure. At
first, it seems a little odd because function arguments in C are
by value only, so it wouldn't matter if it's an lvalue. But in
C++, you can call by reference, so maybe it could matter.
For instance:
void increment (int& n)
{
n++;
}
int myfunction ()
{
int a;
increment (a = 1);
std::cout << "a is " << a << std::endl;
}
I might be wrong (I don't know the C++ specification by heart), but
I believe this is valid C++ code and it prints "a is 2".
What's going on is this:
(1) increment() needs to be called, so...
(2) "a = 1" is evaluated, causing the side-effect of modifying "a"
to be 1. the value of the "a = 1" expression is the value of
"a", which is numerically 1 and also an lvalue.
(3) The lvalue is passed by reference to increment(), which
then uses it to modify "a".
Of course, this is very very bad style and highly confusing code,
but the point is that if it's legal like I think it is, then the
compiler might be putting "{lval}" in the error message on purpose,
because it might actually mean something in some cases. Hmm,
in particular it might be helpful if you try to pass a value
which isn't an lvalue to a function that (because of a reference
type on its argument) requires one.
- Logan
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/