I think the C program below will output 1 :
#include <stdio.h> int main() { unsigned int n=18u; while ((n+17u)>=17u) n-=17u; printf("%u\n",n+17u); return 0; }
But compiled in VC6, Visual Studio 2010 or Visual Studio 2012, all in release mode, the program does not output anything and does not exit.
This is the build code generated by VS2012:
00BD1000 mov eax,12h 00BD1005 lea eax,[eax-11h] 00BD1008 jmp main+5h (0BD1005h)
It seems that the compiler has done some optimization and generated an infinite loop.
I think that ((n+17u)>=17u) not always true, because if n==0xFFFF..FF , n+17u up to 16u .
Am I wrong or are the compilers wrong?
source share