bug.c
#include <stdio.h>
int main()
{
int x = 0x7fffffff;
printf("%x\n", x);
printf("%x\n", ~x);
printf("%x\n", ~x + ~x);
printf("%x\n", !(~x + ~x));
}
I compile using gcc -m32 bug.c -o bug This outputs:
7fffffff
80000000
0
0
It should output
7fffffff
80000000
0
1
I am using gcc 9.3 and gcc-multilib on Ubuntu 20.04. I have also tested this with gcc8 and gcc10. The output was correct when I used clang. Does anyone have any idea why this is happening?