Informix Error -4156: Warning: The loop counter may overflow.
Cause and resolution
Warning: The loop counter may overflow.
This warning can occur for a FOR statement when the upper limit of the FOR loop is within the STEP value of the maximum value of that type. As an example, suppose the FOR statement tried to run IX from 1 to 32760 with a step of 20, and IX was declared as SMALLINT; the compiler would issue the warning because IX would overflow without satisfying the loop termination condition.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4156 is a compiler warning: per the official guidance, this can occur for a FOR statement
when the loop's upper limit is within the STEP value of that type's maximum. For example, a
SMALLINT loop counter running from 1 to 32760 with a step of 20 would overflow before
satisfying the loop's termination condition.
- A
FORloop counter whose upper limit is close enough to its type's maximum that theSTEPcould overshoot it, per the official guidance — the direct cause.
Solutions / Resolution
- Use a wider integer type for the loop counter, or adjust the loop's bounds/step so it can't overflow.
Examples
A loop counter close to overflow
DEFINE ix SMALLINT
FOR ix = 1 TO 32760 STEP 20
...
END FOR
-- -4156: ix may overflow SMALLINT's maximum before the loop terminates
Corrected
DEFINE ix INTEGER
FOR ix = 1 TO 32760 STEP 20
...
END FOR
Diagnostic Checks
- Check every
FORloop's counter type, upper limit, and step for the possibility of overflow, and widen the type or adjust the bounds if needed.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -4156 in this set yet.
A FOR loop's counter may overflow its declared type before the loop terminates — widen the
type or adjust the bounds/step.