#include #include void compare (int a) { if ((a+1) > a) printf("%d > %d\n", (a+1), a); else printf("%d <= %d\n", (a+1), a); } int main () { /* * When compiled with gcc -O0, I get different results for * both lines. With gcc -O1, I get the same. When compiling * with clang, I even more surprising results. * * Surprisingly (or not), these results do not correspond to * bugs in the compilers. * * The warning given by both compilers helps understanding * what's going on, but I had to read the standard to really * get it. */ int i = 33; printf("%d\n", 1 << 33); printf("%d\n", 1 << i); /* * adapted from http://blog.regehr.org/archives/213 * * Try compiling this with -O0 and with -O3, and see ... * Again, no compiler bug involved! */ compare(1); compare(INT_MAX); }