The following program gives incorrect output when compiled with optimization on x86 machine#include <stdio.h>#include <limits.h>int main(int argc, char *argv[]){ volatile int i10 = 10; printf("%d\n", -(INT_MIN/i10)); getchar();}The problem seems to be the following:During the optimization process, the compiler tries to save the '-' at the end of the calculation by changing the sign of the constant dividend first instead. It is ok for all constant ints except INT_MIN because of the 2's complement feature: -INT_MIN==INT_MIN and the result of (-INT_MIN)/10 is negative. The output of the program is correct for other constants, and when the optimization if off (Debug)
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results