Bitwise Leftshift (<<) strange behavior

后端 未结 6 944
鱼传尺愫
鱼传尺愫 2021-01-15 13:41

gcc bitwise Leftshift (<<) strange behavior. Here is my code:

#include 
#include 

void foo(in         


        
6条回答
  •  情书的邮戳
    2021-01-15 13:59

    I finally figure out a work-around solution, at least make the output identical.

    #include 
    #include 
    
    void foo(int n){
      printf("1<<32:%d\n", 1<<32);
      printf("1<<(32-n):%d\n", (1<<(31-n))<<1);
    }
    
    int main(){
        foo(0);
    }
    

提交回复
热议问题