have a peek at this. The compiler is complaining that I have an integer overflow, but when I look at the C89 standard's rules for integral promotion along with the values in that expression, it seems to me that there is no overflow.
rutski@imac:~$ cat test.c
#include <stdio.h>
#include <inttypes.h>
const uint32_t value =
(0x7F-0x00 + 1) * (256 + 256*256 + 256*256*256) +
(0xDF-0xC2 + 1) * (256 + 256*256 + 256*256*256);
int
main(void)
{
printf("value = %"PRIu32"\n", value);
return 0;
}
rutski@imac:~$ gcc -std=c89 -pedantic -Wall -Wextra test.c
test.c:5: warning: integer overflow in expression
test.c:6: warning: integer overflow in expression
test.c:6: warning: overflow in constant expression
rutski@imac:~$ ./a.out
value = 2661195264
rutski@imac:~$
Moreover, google confirms that the answer of 2661195264 is the correct value for that expression! (See this link)
So, how is it that the program can produce a correct value when there was integer overflow? And more importantly, how is it that there was integer overflow in that expression to begin with?