TITLE: l/rvalues in C and C++ (Newsgroups: comp.std.c++, 16 Oct 96) PROBLEM: is83020@cis.nctu.edu.tw (Cheng-hsien Chang) There are some operator treat L-value and R-value differently between C++ and C. RESPONSE: kanze@gabi-soft.fr (J. Kanze) Some operators didn't result in an lvalue in C do in C++. Prefix incrementation and decrementation, and assignment, are examples. In C, an operator results in an lvalue if and only if there would be some way of legally using the results when the operator is applied to built-in types. In C++, an operator results in an lvalue in all cases where the operator itself manipulates an lvalue, and the results of the operator are equal to the value of the lvalue object. (Thus, for example, prefix ++ results in an lvalue, because the results are equal to the value of the object, whereas postfix ++ is not an lvalue, because the results correspond to the previous value, and not the current value.) Note that the examples that you cite ("++++a" and "(a=2)=3)", where "a" is an int) are illegal in both C and C++, but for different reasons. In C, the results of the first operation are not an lvalue, and the second operator requires an lvalue. A constraint has been violated, and a diagnostic is required. In C++, both of these expressions attempt to modify the same object twice without an intervening sequence point, and so result in undefined behavior. I think that for the basic types, all expressions that would be illegal in C are also illegal in C++. On the other hand, there is some justification for the "lvalue-ness" when classes are considered. If "a" and "b" have class type, for example: (a = b).c = x ; If "c" has a user defined operator=, for example, there is a function call before the second modification of the (c in the) a object; this function call is a sequence point, and makes the above defined.