gcc bitwise Leftshift (<<) strange behavior. Here is my code:
#include <stdio.h> #include <string.h> void foo(int n){ printf("1<<32:%d\n", 1<<32); printf("1<<(32-n):%d\n", 1<<(32-n)); } int main(){ foo(0); } If I pass 0 as parameter, the result could be different. Compiling the source code:
$gcc main.c -o demo -lm -pthread -lgmp -lreadline 2>&1 main.c: In function 'foo': main.c:5:3: warning: left shift count >= width of type [enabled by default] Executing the program:
$demo 1<<32:0 1<<(32-n):1 This result is what I've got from compile online site
How can I make the foo function output 0 if I pass 0 to it? (currently it outputs 1 instead)