3 ms·
Yes, that example is well-known but different; here, the compiler is assuming that x + 1 will always be greater than x, which is entirely something else than th
by userbinator 9y ago
Yes, that example is well-known but different; here, the compiler is assuming that x + 1 will always be greater than x, which is entirely something else than the parent's assertion of assuming that x + small_increment will always be positive.
- loup-vaillant 9y agoThe difference doesn't matter, you would know better if you weren't clinging so hard to your beliefs. Here's the "difference": $ cat undefined.c #include <limits.h> #include <stdio.h> #include <stdlib.h> int main() { int x = INT_MAX; if (x+1 < 0) { printf("%d < 0\n", x+1); } else { printf("overflow!\n"); } } $ gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc undefined.c && ./a.out -2147483648 < 0 $ gcc -O3 undefined.c && ./a.out overflow! The security check is gone all the same.