Expressions "j = ++(i | i); and j = ++(i & i); should be a lvalue error?

前端 未结 5 1650
心在旅途
心在旅途 2020-12-02 22:03

I was expecting that in my following code:

#include 
int main(){
    int i = 10; 
    int j = 10;

    j = ++(i | i);
    printf(\"%d %d\\n\         


        
5条回答
  •  Happy的楠姐
    2020-12-02 22:57

    I don't think at all it is an optimization error, because if it was, then there should not be any error in the first place. If ++(i | i) is optimized to ++(i), then there should not be any error, because (i) is an lvalue.

    IMHO, I think that the compiler sees (i | i) as an expression output, that, obviously, outputs rvalue, but the increment operator ++ expects an lvalue to change it, thus the error.

提交回复
热议问题