bregma
16 hours ago
We use this question in technical interviews (we hire compiler developers for whom this sort of esoteric knowledge is daily bread).
It illustrates one of the incompatibilities between the C programming language and the C++ programming language. In C, the result of the comma operator is always an rvalue so it's not a valid assignment. In C++, it's an rvalue reference , which can be effectively thought of as an lvalue (without going through the convoluted value category reasoning specified by the standard which will leave anyone stymied), so it's a valid assignment.
The problems come when people think "C++ is just a superset of C" and don't know what they're talking about.
plorkyeran
11 hours ago
This doesn't seem like an example of C++ not being a superset of C? While there's a significant difference in how the comma operator is specified between the two languages, the C++ behavior is a superset of the C behavior. The C++ behavior is only different for constructs which aren't legal C.
boywitharupee
16 hours ago
> In C++, it's an rvalue reference , which can be effectively thought of as an lvalue
hmm...this doesn't sound quite right? the comma operator's result in C++ is not an rvalue reference - it takes on exactly the value category of its right operand (which in this case is an lvalue)