Re: returning lvalue in C vs C++



* Ben C:

f().x is _not_ an invalid lvalue, it's a perfectly good lvalue.

I'm sorry, that's incorrect -- it's not an lvalue at all, it's an rvalue.


It looks
like the error is based on the assumption that any function return value
is an rvalue. This assumption is harmless in C because there's never any
point assigning to a return value. In C++ where you can return
references and overload operator= for user-defined types to cause
sideeffects, the compiler has to be more careful about what it does and
doesn't allow and look a bit more carefully at assignments like this.

Yes, but the above function does not return a reference.

It returns a value, pure and simple.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.