Mark Dickinson <dicki...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10044>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to