Compiler Warnings
Olson, Arthur David (NIH/NCI) [E]
olsona at dc37a.nci.nih.gov
Wed Apr 13 13:38:40 UTC 2011
Here’s an "increment_overflow" replacement that doesn't get any complaints from gcc.
How can it be portably simplified?
--ado
static int
increment_overflow(ip, j)
register int * const ip;
register int j;
{
register int i, halfsum, halfmod, bothneg;
i = *ip;
*ip += j;
if (i == 0 || j == 0) {
return 0;
}
if ((i > 0) != (j > 0)) {
return 0;
}
bothneg = i < 0;
if (bothneg) {
if (i == INT_MIN || j == INT_MIN)
return 1;
i = -i;
j = -j;
}
halfsum = (i / 2) + (j / 2);
halfmod = (i % 2) + (j % 2);
if (halfmod == 2) {
++halfsum;
halfmod = 0;
}
if (bothneg) {
if (halfsum < -(INT_MIN / 2))
return 0;
if (halfsum > -(INT_MIN / 2))
return 1;
return ((INT_MIN % 2) == 0) ? halfmod : 0;
} else {
if (halfsum < (INT_MAX / 2))
return 0;
if (halfsum > (INT_MAX / 2))
return 1;
return ((INT_MAX % 2) == 0) ? halfmod : 0;
}
}
More information about the tz
mailing list