Since when does GCC *assume* the program to be correct?
Posted Apr 17, 2008 19:38 UTC (Thu) by
brouhaha (subscriber, #1698)
Parent article:
GCC and pointer overflows
This behavior is allowed by the C standard, which states that, in a correct program, pointer addition will not yield a pointer value outside of the same object. So the compiler can assume that the test for overflow is always false and may thus be eliminated from the expression.
GCC can only assume that the test for overflow is always false if it first assumes that the program is correct. Since when does it assume that? If GCC
assumes that the program is correct, why does it sometimes generate errors and/or warnings at compile time? Correct programs won't require any error or warning messages at compile time, so there's no point in GCC having any code to check for the conditions that can cause those errors and warnings. Clearly it would be more efficient for GCC to avoid those checks, so they should be eliminated.
(
Log in to post comments)