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

前端 未结 5 1648
心在旅途
心在旅途 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条回答
  •  一向
    一向 (楼主)
    2020-12-02 23:04

    This is a bug that has been addressed in more recent GCC versions.

    It's probably because the compiler optimizes i & i to i and i | i to i. This also explains why the xor operator didn't work; i ^ i would be optimized to 0, which is not a modifiable lvalue.

提交回复
热议问题