Message118139
| Author |
mark.dickinson |
| Recipients |
amaury.forgeotdarc, eric.smith, mark.dickinson, pitrou, rhettinger, stutzbach |
| Date |
2010年10月07日.21:22:02 |
| SpamBayes Score |
1.4077406e-11 |
| Marked as misclassified |
No |
| Message-id |
<1286486523.86.0.587248442341.issue10044@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
See the example above: suppose that a compiler is looking at a (p >= q) comparison of pointers. Suppose furthermore that in a particular case that compiler is smart enough to figure out that q is a pointer to the start of an array. Then the compiler is *permitted to assume* that p also points into the same array, since if it didn't then the code would introduce undefined behaviour. And since q is the start of the array, and p is (by assumption) a pointer into the same array, p >= q will automatically be true, so the compiler is free to replace the expression with the integer '1' (i.e., true).
gcc does similar things with checks like (x + 1 > x): if x is a (signed) int, then gcc can and will optimize (x + 1 > x) to 'true', on the basis that x + 1 can never overflow, because such overflow would be undefined behaviour and therefore can't occur in a valid C program. |
|