#de" /> #de" /> #de"/>

Why gcc 9.5.0 treates x>x+1 as tautology?

18 views Asked by At

gcc 9.5.0 treates x<x+1 as tautology for "int x".

For the following program, gcc 9.5.0 compiler seems to replaces x<x+1 with 1.

#include <stdio.h>
#define M 0x7FFFFFFF
int main() {
    int x = M;
    printf("%d\n", x<x+1);
    printf("%d\n", x);
    printf("%d\n", x+1);
}

So, the output of the program is

1 2147483647 -2147483648

It was not the case with gcc 5.4.0. gcc 5.4.0 prints 0 as the first output.

  • Why gcc9.5.0 treats x<x+1 always true?
  • Can I disable the replacement?

(For "unsigned x", gcc9.5.0 does not treate x<x+1 as tautology.)

0

There are 0 answers