First, defining two constant expressions without parentheses is my fault:
#define BIG_INTERVAL 60 * 60 * 1000
#define SMALL_INTERVAL 1 * 1000
int i = 1;
if (i >= BIG_INTERVAL / SMALL_INTERVAL - 1)
{
printf("Oops!\n");
}
The if statement after the macro expansion is if(i >= 60 * 60 * 1000 / 1 * 1000 - 1).
That is not my intention. But I find something strange if I write if (i >= 3600000000 - 1). It is false.
What type is 60 * 60 * 1000 / 1 * 1000 - 1 ? int?
All operators on
ints returnint. So yes,60 * 60 * 1000 / 1 * 1000 - 1is anint. But the expected result of 3599999999 is too big for anint, so the expression actually evaluates to -694967297 (assuming 32-bitintand two’s complement).This doesn’t happen with a literal
3600000000because integer literals larger thanINT_MAXare of a type that can hold the full value.