...
This compliant solution does not depend on undefined behavior because it generates code to test for overflow in the assertion.
| Code Block | ||
|---|---|---|
| ||
#include <assert.h>
int foo(int a) {
assert(a < (INT_MAX - 100));
printf("%d %d\n", a + 100, a);
return a;
}
int main(void) {
foo(100);
foo(INT_MAX);
}
|
...