Author says that the following code is how to check for overflow:
if ((INT32_MAX / 0x1ff) <= x) {
printf("overflow prevented!\n");
return 0;
}
But didn't the original problem arise because the compiler assumed overflow could never happen and simply optimized out the "undefined behavior"? What's to prevent compilers from optimizing out this check for similar reasons?