Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KristianLyng/ef265e19e68633c072ebde65589c00ad to your computer and use it in GitHub Desktop.
Save KristianLyng/ef265e19e68633c072ebde65589c00ad to your computer and use it in GitHub Desktop.
kly@leia:~$ cat foo.c
#include <stdio.h>
#include <limits.h>
int main() {
int si = INT_MAX;
unsigned int ui = UINT_MAX;
printf ("si: %d (INT_MAX)\n", si);
printf ("ui: %u (UINT_MAX)\n", ui);
if (si > si + 1)
printf("si larger than si + 1\n");
else
printf("si not larger than si + 1\n");
if (ui > ui + 1)
printf("ui larger than ui + 1\n");
else
printf("ui not larger than ui + 1\n");
return 0;
}
kly@leia:~$ gcc foo.c -O2 -o test-O2
kly@leia:~$ gcc foo.c -O0 -o test-O0
kly@leia:~$ ./test-O0
si: 2147483647 (INT_MAX)
ui: 4294967295 (UINT_MAX)
si larger than si + 1
ui larger than ui + 1
kly@leia:~$ ./test-O2
si: 2147483647 (INT_MAX)
ui: 4294967295 (UINT_MAX)
si not larger than si + 1
ui larger than ui + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment